Offline screen auto reconnect

This commit is contained in:
sewmina7@gmail.com 2023-08-16 20:57:28 +05:30
parent 0ada78e781
commit 68d313de01
4 changed files with 36 additions and 8 deletions

View File

@ -54,7 +54,7 @@ android {
applicationId "com.Xperience.FaucetHub" applicationId "com.Xperience.FaucetHub"
// You can update the following values to match your application needs. // 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. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName

View File

@ -1,5 +1,9 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:external_app_launcher/external_app_launcher.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/src/CustomWidgets.dart';
import 'package:fhub/welcome.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class OfflinePage extends StatefulWidget { class OfflinePage extends StatefulWidget {
@ -8,7 +12,7 @@ class OfflinePage extends StatefulWidget {
@override @override
State<OfflinePage> createState() => _OfflinePageState(); State<OfflinePage> createState() => _OfflinePageState();
} }
var subscription;
class _OfflinePageState extends State<OfflinePage> { class _OfflinePageState extends State<OfflinePage> {
@override @override
@ -17,6 +21,29 @@ class _OfflinePageState extends State<OfflinePage> {
super.initState(); super.initState();
kickstartAnimations(); 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 { void kickstartAnimations() async {
@ -41,9 +68,11 @@ class _OfflinePageState extends State<OfflinePage> {
}, },
context: context, context: context,
child: Padding( child: SafeArea(
padding: const EdgeInsets.all(24.0), child: Padding(
child: id == 0 ? NoInternet() : ( id == 1 ? NewUpdate():Maintaince()) padding: const EdgeInsets.all(24.0),
child: id == 0 ? NoInternet() : ( id == 1 ? NewUpdate():Maintaince())
),
), ),
)); ));
} }

View File

@ -34,7 +34,7 @@ class _MyHomePageState extends State<MyHomePage> {
try{ try{
final connectivityResult = await (Connectivity().checkConnectivity()); final connectivityResult = await (Connectivity().checkConnectivity());
Debug.Log(connectivityResult); 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))); Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_)=>OfflinePage(id:0)));
return; return;
@ -55,7 +55,6 @@ class _MyHomePageState extends State<MyHomePage> {
void init() async{ void init() async{
int serverVersion = await DataManager.GetVersion(); int serverVersion = await DataManager.GetVersion();
if(serverVersion > 0 && serverVersion != DataManager.ClientVersion){ if(serverVersion > 0 && serverVersion != DataManager.ClientVersion){
Navigator.of(context).push(MaterialPageRoute(builder: (context)=> UpdatePage())); Navigator.of(context).push(MaterialPageRoute(builder: (context)=> UpdatePage()));

View File

@ -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 # 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 # 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. # 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: environment:
sdk: '>=3.0.1 <4.0.0' sdk: '>=3.0.1 <4.0.0'