From 68d313de01fc7d1e60cdaf0e30d80f852699ea19 Mon Sep 17 00:00:00 2001 From: "sewmina7@gmail.com" Date: Wed, 16 Aug 2023 20:57:28 +0530 Subject: [PATCH] Offline screen auto reconnect --- android/app/build.gradle | 2 +- lib/off_screen.dart | 37 +++++++++++++++++++++++++++++++++---- lib/welcome.dart | 3 +-- pubspec.yaml | 2 +- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index d3a8776..623675d 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -54,7 +54,7 @@ android { applicationId "com.Xperience.FaucetHub" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion flutter.minSdkVersion + minSdkVersion 19 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/lib/off_screen.dart b/lib/off_screen.dart index 484d011..0ec5b95 100644 --- a/lib/off_screen.dart +++ b/lib/off_screen.dart @@ -1,5 +1,9 @@ +import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:external_app_launcher/external_app_launcher.dart'; +import 'package:fhub/backend/DebugHelper.dart'; +import 'package:fhub/home.dart'; import 'package:fhub/src/CustomWidgets.dart'; +import 'package:fhub/welcome.dart'; import 'package:flutter/material.dart'; class OfflinePage extends StatefulWidget { @@ -8,7 +12,7 @@ class OfflinePage extends StatefulWidget { @override State createState() => _OfflinePageState(); } - +var subscription; class _OfflinePageState extends State { @override @@ -17,6 +21,29 @@ class _OfflinePageState extends State { super.initState(); kickstartAnimations(); + + subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) async{ + // Got a new connectivity status! + try{ + final connectivityResult = await (Connectivity().checkConnectivity()); + Debug.Log(connectivityResult); + if(connectivityResult == ConnectivityResult.mobile || connectivityResult == ConnectivityResult.wifi || connectivityResult == ConnectivityResult.ethernet || connectivityResult == ConnectivityResult.vpn){ + Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_)=>MyHomePage())); + + return; + } + }catch(e){ + + } + }); + } + + @override + void dispose() { + // TODO: implement dispose + super.dispose(); + + subscription.cancel(); } void kickstartAnimations() async { @@ -41,9 +68,11 @@ class _OfflinePageState extends State { }, context: context, - child: Padding( - padding: const EdgeInsets.all(24.0), - child: id == 0 ? NoInternet() : ( id == 1 ? NewUpdate():Maintaince()) + child: SafeArea( + child: Padding( + padding: const EdgeInsets.all(24.0), + child: id == 0 ? NoInternet() : ( id == 1 ? NewUpdate():Maintaince()) + ), ), )); } diff --git a/lib/welcome.dart b/lib/welcome.dart index bf7214a..9d3b0cb 100644 --- a/lib/welcome.dart +++ b/lib/welcome.dart @@ -34,7 +34,7 @@ class _MyHomePageState extends State { try{ final connectivityResult = await (Connectivity().checkConnectivity()); Debug.Log(connectivityResult); - if(connectivityResult != ConnectivityResult.mobile && connectivityResult != ConnectivityResult.mobile && connectivityResult != ConnectivityResult.ethernet){ + if(connectivityResult != ConnectivityResult.mobile && connectivityResult != ConnectivityResult.wifi && connectivityResult != ConnectivityResult.ethernet && connectivityResult != ConnectivityResult.vpn){ Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_)=>OfflinePage(id:0))); return; @@ -55,7 +55,6 @@ class _MyHomePageState extends State { void init() async{ - int serverVersion = await DataManager.GetVersion(); if(serverVersion > 0 && serverVersion != DataManager.ClientVersion){ Navigator.of(context).push(MaterialPageRoute(builder: (context)=> UpdatePage())); diff --git a/pubspec.yaml b/pubspec.yaml index b6a210a..8790df4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 +version: 1.0.2+2 environment: sdk: '>=3.0.1 <4.0.0'