I have a page in my app that has some icons and animations on how to use the app.
I want to load this page on the first launch after installation and then I want any other launch of the app to go straight to the home page.
How can this be done?
I have seen a couple threads that confuse this question with splash screens, I only want this page to be launched once after installation and then never again.
Thank you
Asked
Active
Viewed 185 times
1

flutterNoob
- 67
- 1
- 9
1 Answers
1
You must create splash screen and in this page check the shared preference that tell you if you already showed intro page or not if you showed that page you can navigate to main page otherwise navigate to intro page in intro page show whatever you want to show and in when introduction is over set the isIntroShowed or to true on shared preference like below code
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SplashScreen(),
);
}
}
class SplashScreen extends StatefulWidget {
SplashScreen({Key key}) : super(key: key);
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
SharedPreferences.getInstance().then((prefs){
var isShowed =prefs.getBool("isIntroShowed");
if(isShowed!=null && isShowed)
{
//navigate to main page
}
else{
//navigate to intro page
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: CircularProgressIndicator(),),
);
}
}
class IntroPage extends StatelessWidget {
const IntroPage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child:FlatButton(child: Text('intro done'),onPressed: ()async{
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('isIntroShowed', true);
// navigate to main content
},)
),
);
}
}

Ali mohammadi
- 1,839
- 26
- 27
-
Just one thing, it creates a back button in my menu bar to go back to this loading screen on the next runs, and the back button on android also takes it back to this screen. Any way I can fix this? – flutterNoob Mar 22 '20 at 14:16
-
1Never mind, used this link: https://stackoverflow.com/questions/45916658/how-to-deactivate-or-override-the-android-back-button-in-flutter. Thanks again for the help – flutterNoob Mar 22 '20 at 14:38
-
Oh i missed that , you can navigate with this pushAndRemoveUntil method of fluatter navigator – Ali mohammadi Mar 22 '20 at 21:43