Want to check if an application is on its first run with flutter? Use Shared Preferences Package. You can read it with FutureBuilder, and you can check if there is a bool named welcome for example. This is the implementation I have in my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
return new FutureBuilder<SharedPreferences>( future: SharedPreferences.getInstance(), builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: case ConnectionState.waiting: return new LoadingScreen(); default: if (!snapshot.hasError) { @ToDo("Return a welcome screen") return snapshot.data.getBool("welcome") != null ? new MainView() : new LoadingScreen(); } else { return new ErrorScreen(error: snapshot.error); } } }, ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.