main function

void main()

Implementation

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform
  );



  await _requestAllMediaPermissions();
  if(Platform.isAndroid){
    messaging = FirebaseMessaging.instance;
    await messaging.requestPermission();
  }

  if(Platform.isAndroid){
    String? fcmToken = await messaging.getToken();
    if (kDebugMode) {
      print("🎉 FCM Token: $fcmToken");
    }
  }


  final router = GoRouter(
    navigatorKey: navigatorKey,
    initialLocation: '/',
    redirect: (BuildContext context, GoRouterState state) async {
      final prefs = await SharedPreferences.getInstance();
      final isLoggedIn = prefs.getBool('isAuthenticated') ?? false;
      final loggingIn = state.fullPath == '/LoginScreen';

      // If not logged in, go to login
      if (!isLoggedIn && !loggingIn) {
        return '/LoginScreen';
      }

      // If logged in but trying to access login page, redirect to home
      if (isLoggedIn && loggingIn) {
        return '/HomeScreenControllState';
      }

      return null; // Allow navigation
    },
    routes: [
      GoRoute(path: '/', builder: (_, __) => AuthCheck()),
      GoRoute(path: '/HomeScreenControllState', builder: (_, __) => HomeScreenControllState()),
      GoRoute(path: '/LoginScreen', builder: (_, __) => LoginScreen()),
      GoRoute(path: '/Allemployeeinformation', builder: (context, state) {
        final idStr = state.uri.queryParameters['id'];
        final id = idStr ?? '';
        if (id == '') {
          return const Scaffold(body: Center(child: Text("Invalid ID")));
        }

        return EmployeeLoader(id: id);    // 🔥 Pass it to the screen
      },),
    ],
  );

  runApp(StoreProvider(
    store: store,
    child: MyApp(router: router, store: store),
  ));
}