This question really, really similar like this one. I have followed the accepted answer but nothing happen.
I try to modify my first landing page on main.dart whether it's HomePage() or OnBoardingPage(). I'm getting data (bool) from Shared Preferences and do the checking first.
As you can see, the OnBoardingPage() is just a one-time-event screen.
Here the code:
class MyApp extends StatelessWidget {
SharedPrefs prefs = SharedPrefs();
Future<bool> _initBro() async {
var redirect = await prefs.read("onboard") ?? false;
print("main => $redirect");
return redirect;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
fontFamily: 'CM Sans Serif',
platform: TargetPlatform.android,
),
home: (_initBro().then(val => val == true)) ? HomePage() : OnBoardingPage(),
// home: HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
The problem is on the home: line.
I don't quite understand why it still giving me such error. I have changed the code with await but, seems its giving me much more trouble. Also I have modified it a bit like this:
home: _initBro().then((val) {
return (val) ? HomePage() : OnBoardingPage();
}),
But still no hope.
I'm new with Flutter and absolutely also with Dart. Any help would be really appreciated.
Thank you very much for paying attention guys.
