I want to show this login screen only on the first start up. After that it s possible to come to login screen by pressing "Account" button in another widget, I already did that. Only the shared prefs bool is my problem: I dont know where do I have to implement the bool, and how do i sent it to the root widget. Let me show the code:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await init();
SharedPreferences prefs = await SharedPreferences.getInstance();
return runApp(ChangeNotifierProvider(
child: const MyApp(),
create: (BuildContext context) => ThemeService(
isSysModeOn: prefs.getBool("isSystemMode") ?? true, isDarkOn: prefs.getBool("isDarkModeOn") ?? true)));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider(create: (context) => NavbarCubit()),
BlocProvider(create: (context) => sl<SignupBloc>()),
BlocProvider(create: (context) => DrinkCubit()),
],
child: Consumer<ThemeService>(builder: (context, themeService, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: themeService.getSysMode
? ThemeMode.system
: (themeService.getDarkMode ? ThemeMode.dark : ThemeMode.light),
home: first_time ? const SignUpPage() : RootWidget());
}),
);
}
}
the if question in the home: is manuall added, not working. I know i already did nearly the same thing with the Theme Data as you can see in the void main :D But how do I ask
bool first_time = true;
if(user_firstime_started_app == true){
first_time = false;
prefs.setBool(.....
....
}
something like this.
CodePudding user response:
You can show a splash screen while you check if the user is logged in. If the user is logged in then replace and navigate to the home page or the login page.
Refer to this answer and replace the logic of seen with the logic of is logged in: https://stackoverflow.com/a/50655196/2008962.