my app has a login page and logs in the user with an access token. At the start of the app, if user still has a token(which means did not logged out since last login), home page is X but if user does not have token home page is login page. There was no problem since I was using SharedPreferences to store the token but I decided to use flutter_secure_storage package. It's functions work async. So the problem is, after I changed SharedPreferences to flutter_secure_storage, if user does not have token and starts the app, page X is showing for a couple of seconds and then login page is coming. I used async/await functions for all flutter_secure_storage variables but can not use it for home page. I assumed it is because I can not make the app await for token check, it starts building page X and then realizes token is null and then builds login page.That may not be true, just my thought. My code for home: is
home: Constants.storage.read(key: "token") !=
null
? ChangeNotifierProvider(
create: (context) => BooksPageViewModel(),
child: BooksView(),
)
: ChangeNotifierProvider(
create: (context) => LoginPageViewModel(),
child: LoginPage(),
));
I tried to make a Future function but can't assigned it to home: ... I tried to make home: ... async but didn't happened. How can I set my home page to await for token check? Thanks in advance.