165 lines
5.6 KiB
Dart
165 lines
5.6 KiB
Dart
import 'package:external_repos/external_repos.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:uae_stat/config/injector.dart';
|
|
import 'package:uae_stat/config/my_router.dart';
|
|
import 'package:uae_stat/config/my_theme.dart';
|
|
import 'package:uae_stat/config/old_theme.dart';
|
|
import 'package:uae_stat/domain/entities/language_locale.dart';
|
|
import 'package:uae_stat/domain/use_cases/auth_use_case.dart';
|
|
import 'package:uae_stat/infrastructure/services/InternetConnectivity_Service/InternetConnectivityService.dart';
|
|
import 'package:uae_stat/presentation/Screens/online_offline_verification/internet_check.dart';
|
|
import 'package:uae_stat/presentation/Screens/profilepage.dart';
|
|
import 'package:uae_stat/presentation/Screens/auth_verification/registration.dart';
|
|
import 'package:uae_stat/presentation/components/indicators/locale_provider.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
// void main() async {
|
|
// WidgetsFlutterBinding.ensureInitialized();
|
|
// // await (await SharedPreferences.getInstance()).clear();
|
|
// configureDependencies();
|
|
// runApp(
|
|
// const ProviderScope(
|
|
// child: MainApp(),
|
|
// ),
|
|
// );
|
|
// }
|
|
//
|
|
// class MainApp extends ConsumerWidget {
|
|
// const MainApp({super.key});
|
|
//
|
|
// @override
|
|
// Widget build(BuildContext context, WidgetRef ref) {
|
|
// final locale = ref.watch(localeProvider);
|
|
//
|
|
// return MaterialApp.router(
|
|
// debugShowCheckedModeBanner: false,
|
|
// routerConfig: router,
|
|
// locale: locale,
|
|
// localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
// supportedLocales: AppLocalizations.supportedLocales,// Use the GoRouter instance from app_router.dart
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// void main() async {
|
|
// WidgetsFlutterBinding.ensureInitialized();
|
|
// // await (await SharedPreferences.getInstance()).clear();
|
|
// configureDependencies();
|
|
// runApp(
|
|
// const ProviderScope(
|
|
// child: MainApp(),
|
|
// ),
|
|
// );
|
|
// }
|
|
//
|
|
// class MainApp extends ConsumerWidget {
|
|
// const MainApp({super.key});
|
|
//
|
|
// @override
|
|
// Widget build(BuildContext context, WidgetRef ref) {
|
|
// final locale = ref.watch(localeProvider);
|
|
//
|
|
// // Listen to connectivity changes at the app level
|
|
// ref.listen<bool>(connectivityProvider, (previous, hasInternet) {
|
|
// if (previous != null && !hasInternet) {
|
|
// // When no internet, navigate to the NoInternetScreen
|
|
// print('No Internet Connection');
|
|
// context.go('/internetcheck');
|
|
//
|
|
// } else if (previous != null && hasInternet) {
|
|
// // If internet is back, navigate back to the HomeScreen
|
|
// print("You have an Internet connection");
|
|
// context.go('/myhomepage');
|
|
//
|
|
// }
|
|
// });
|
|
//
|
|
// return MaterialApp.router(
|
|
// debugShowCheckedModeBanner: false,
|
|
// routerConfig: router, // Assuming you are using GoRouter
|
|
// locale: locale,
|
|
// localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
// supportedLocales: AppLocalizations.supportedLocales,
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
// Handle background messages
|
|
print("Handling background message: ${message.messageId}");
|
|
}
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await Firebase.initializeApp(
|
|
options: const FirebaseOptions(
|
|
apiKey: 'AIzaSyB-QQbnq366f7rrKLVVFJKnSZgR9LcDWFI',
|
|
appId: '1:62132243005:android:18b7ca94608afaeb7c7854',
|
|
messagingSenderId: '62132243005',
|
|
projectId: 'fcsc-a161c'));
|
|
|
|
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
|
|
|
// Request permission for notifications
|
|
NotificationSettings settings = await messaging.requestPermission(
|
|
alert: true,
|
|
badge: true,
|
|
sound: true,
|
|
);
|
|
|
|
print('User granted permission: ${settings.authorizationStatus}');
|
|
configureDependencies();
|
|
runApp(
|
|
const ProviderScope(
|
|
child: MainApp(),
|
|
),
|
|
);
|
|
}
|
|
class MainApp extends ConsumerWidget {
|
|
const MainApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final locale = ref.watch(localeProvider);
|
|
|
|
final connectivityProvider = Provider<bool>((ref) {
|
|
return true; // Replace with actual logic
|
|
});
|
|
|
|
ref.listen<bool>(connectivityProvider, (previous, hasInternet) {
|
|
print('Previous Internet Status: $previous');
|
|
print('Current Internet Status: $hasInternet');
|
|
if (previous != null && hasInternet != previous) {
|
|
handleConnectivityChange(context, hasInternet);
|
|
}
|
|
});
|
|
|
|
return MaterialApp.router(
|
|
debugShowCheckedModeBanner: false,
|
|
routerConfig: router,
|
|
locale: locale,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
);
|
|
}
|
|
|
|
void handleConnectivityChange(BuildContext context, bool hasInternet) {
|
|
//final currentPath = GoRouter.of(context).location;
|
|
final currentPath =
|
|
GoRouter.of(context).routerDelegate.currentConfiguration.fullPath;
|
|
if (!hasInternet && currentPath != '/internetcheck') {
|
|
print("Status : Not connected");
|
|
context.go('/internetcheck');
|
|
} else if (hasInternet && currentPath != '/login') {
|
|
print("Status : Internet connected");
|
|
context.go('/login');
|
|
}
|
|
}
|
|
}
|