delay / flutter_starter

MIT License
422 stars 146 forks source link

Splash UI #29

Open faviasono opened 1 year ago

faviasono commented 1 year ago

Hi, could you please explain to me how you connected the Splash UI defined as initial route ('/') in GetMaterialApp? I do not understand how you get to login page if you have not defined a "home" parameter in GetMaterialApp.

Cheers, Andrea

delay commented 1 year ago

app routes are defined here. https://github.com/delay/flutter_starter/blob/b34120adcfdb363699aab40d4561701be2ba5b5c/lib/constants/app_routes.dart

and the initial route is set in main.dart

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ThemeController.to.getThemeModeFromStore();
    return GetBuilder<LanguageController>(
      builder: (languageController) => Loading(
        child: GetMaterialApp(
          translations: Localization(),
          locale: languageController.getLocale, // <- Current locale
          navigatorObservers: [
            // FirebaseAnalyticsObserver(analytics: FirebaseAnalytics()),
          ],
          debugShowCheckedModeBanner: false,
          //defaultTransition: Transition.fade,
          theme: AppThemes.lightTheme,
          darkTheme: AppThemes.darkTheme,
          themeMode: ThemeMode.system,
          initialRoute: "/",
          getPages: AppRoutes.routes,
        ),
      ),
    );
  }
}
faviasono commented 1 year ago

Thanks! I am still learning GetX. I noticed the AppRoutes.routes constant and I see '/' is mapped to SplashUI. I just don't see when/how the login page is called from SlashUI (or how a login controller handles that).

I appreciate your help! Cheers

delay commented 1 year ago

To be honest I am probably not the best person to answer this anymore. I haven't really coded in flutter in a couple of years. I am building stuff with sveltekit and vanilla javascript these days. GetX has a bunch of user tutorials at the bottom of this page. https://pub.dev/packages/get#community-channels

salscoding commented 1 year ago

@faviasono I am trying to answer on behalf of @delay as he is busy with other things.

Please go to Lib->Controllers->auth_controller.dart. Check the code after init (i guess). Now you can refer the code and check getX documentation for "Get.off() & Get.offAll()"

Code:

handleAuthChanged(_firebaseUser) async {
    //get user data from firestore
    if (_firebaseUser?.uid != null) {
      firestoreUser.bindStream(streamFirestoreUser());
      await isAdmin();
    }

    if (_firebaseUser == null) {
      print('Send to signin');
      Get.offAll(SignInUI());
    } else {
      Get.offAll(HomeUI());
    }
  }