126 lines
5.1 KiB
Dart
Executable File
126 lines
5.1 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
|
import 'package:uae_stat/config/connectivity_provider.dart';
|
|
import 'package:uae_stat/domain/use_cases/language.dart';
|
|
|
|
class InternetCheckScreen extends ConsumerWidget {
|
|
const InternetCheckScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
ref.listen<AsyncValue<bool>>(connectivityProvider, (previous, hasInternet) {
|
|
if (hasInternet.value == true) {
|
|
// Show a SnackBar when internet is back
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(context.translate('Internet is back!','عاد الاتصال بالإنترنت!')),
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
context.pop();
|
|
// Wait for the SnackBar to be visible before navigating
|
|
// Future.delayed(Duration(seconds: 1), () {
|
|
// if (context.canPop()) {
|
|
// context.pop(); // Go back if there's a previous page
|
|
// } else {
|
|
// context.go(
|
|
// '/myhomepage'); // Redirect to home if no previous page exists
|
|
// }
|
|
// });
|
|
}
|
|
});
|
|
|
|
double myHeight = MediaQuery.of(context).size.height;
|
|
|
|
return PopScope(
|
|
canPop: false,
|
|
onPopInvokedWithResult: (didPop, result) {
|
|
if (didPop) return;
|
|
|
|
},
|
|
child: Scaffold(
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Image.asset('assets/logos/no-internet.png', width: 150),
|
|
SizedBox(height: myHeight / 40),
|
|
Text(context.translate('No Internet Connection','لا يوجد اتصال بالإنترنت'),
|
|
style: TextStyle(fontFamily: context.translate(
|
|
'Roboto',
|
|
'NotoKufi',
|
|
), fontSize: 25, fontWeight: FontWeight.bold),),
|
|
Text(context.translate('Please check your Wi-Fi or Mobile Data','يرجى التحقق من شبكة Wi-Fi أو بيانات الهاتف المحمول'),
|
|
style: TextStyle(fontFamily: context.translate(
|
|
'Roboto',
|
|
'NotoKufi',
|
|
), fontSize: 15, fontWeight: FontWeight.w500),),
|
|
Text(context.translate('connection and try again','واتصالك ثم حاول مرة أخرى'),
|
|
style: TextStyle(fontFamily: context.translate(
|
|
'Roboto',
|
|
'NotoKufi',
|
|
), fontSize: 15, fontWeight: FontWeight.w500),),
|
|
SizedBox(height: myHeight / 40),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
bool hasInternet =
|
|
await InternetConnectionChecker.instance.hasConnection;
|
|
|
|
if (hasInternet) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(context.translate('Internet is back!','عاد الاتصال بالإنترنت!')),
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
context.pop();
|
|
// Future.delayed(Duration(seconds: 1), () {
|
|
// if (context.canPop()) {
|
|
// context.pop();
|
|
// } else {
|
|
// context.go('/myhomepage');
|
|
// }
|
|
// });
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content:
|
|
Text(context.translate('No internet connection. Please try again.','لا يوجد اتصال بالإنترنت. يرجى المحاولة مرة أخرى.')),
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Color(0xFFA7887A),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(10)),
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text( context.translate('Retry','إعادة المحاولة'),
|
|
style: TextStyle(fontFamily: context.translate(
|
|
'Roboto',
|
|
'NotoKufi',
|
|
), fontSize: 16, color: Colors.white),),
|
|
SizedBox(width: 8),
|
|
Icon(Icons.refresh, size: 16, color: Colors.white),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
}
|
|
}
|