Skip to content

Instantly share code, notes, and snippets.

View TarunNagaSai's full-sized avatar
💻
dont think its easy

Tarun Naga Sai TarunNagaSai

💻
dont think its easy
View GitHub Profile
@TarunNagaSai
TarunNagaSai / no_internet_helper_widget.dart
Created January 20, 2023 14:30
this widget is warped aroud the
import 'package:flutter/material.dart';
import 'package:get/instance_manager.dart';
import 'package:no_internet_configuration/UI/screens/no_internet_screen.dart';
import 'package:no_internet_configuration/controller/internet_service_controller.dart';
class CheckInternet extends StatelessWidget {
/// CheckInternet accept the [page] widget and check with internet
/// if available returns page or no internet screen
const CheckInternet({required this.page, required this.routeName, super.key});
@TarunNagaSai
TarunNagaSai / routes.dart
Last active January 20, 2023 18:27
This file has all the routes of the screen and the main configuraiton for all the screen in the app
import 'package:flutter/material.dart';
import 'package:get/get_instance/get_instance.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:no_internet_configuration/UI/screens/home_screen.dart';
import 'package:no_internet_configuration/UI/screens/second_screen.dart';
import 'package:no_internet_configuration/UI/widgets/no_internet_helper.dart';
class GetRoutes {
/// route names
static const home = '/', secondScreen = '/secondScreen';
@TarunNagaSai
TarunNagaSai / no_internet_screen.dart
Last active January 20, 2023 18:21
This page shows the no internet message with a retry button
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:no_internet_configuration/controller/internet_service_controller.dart';
class NoInternetScreen extends StatelessWidget {
/// this class has the code to display no internet screen.
const NoInternetScreen({
Key? key,
required this.routeName,
}) : super(key: key);
@TarunNagaSai
TarunNagaSai / home_screen.dart
Created January 19, 2023 18:48
this is the opening screen of the app with had a button to redirect to the second screen.
import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
import 'package:no_internet_configuration/core/routes.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
@TarunNagaSai
TarunNagaSai / main.dart
Created January 19, 2023 18:46
this is a main dart file of the no_internet_configuration
void main() {
runApp(
GetMaterialApp(
title: AppContnats.siteName,
enableLog: true,
debugShowCheckedModeBanner: false,
defaultTransition: Transition.native,
opaqueRoute: Get.isOpaqueRouteDefault,
popGesture: Get.isPopGestureEnable,
@TarunNagaSai
TarunNagaSai / bindings.dart
Created January 19, 2023 18:36
Using binding to create an instance of the controller will helps to access it in the entire app
import 'package:get/get.dart';
import 'package:no_internet_configuration/controller/internet_service_controller.dart';
/// Initial bindings to the app
class InitialBindings extends Bindings {
@override
void dependencies() {
Get.put<NetworkServicesController>(
NetworkServicesController(),
@TarunNagaSai
TarunNagaSai / internet_service_controller.dart
Created January 19, 2023 18:20
This file has a getx controller which has connectivity stream Subscription which give out the network status.
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
class NetworkServicesController extends GetxController {
bool connectedToNetwork = false;
final Connectivity _connectivity = Connectivity();
late StreamSubscription<ConnectivityResult> _connectivitySubscription;
@TarunNagaSai
TarunNagaSai / pubspec.yaml
Created January 19, 2023 18:00
this gist is to show the dependencies for the no_internet_configuration
dependencies:
flutter:
sdk: flutter
connectivity_plus: ^3.0.2
get: ^4.6.5