Flutter Onboarding Screen Only One Time - Stack Overflow PDF
Flutter Onboarding Screen Only One Time - Stack Overflow PDF
i am new to flutter and dart and i am trying to make an app with an onboarding screen with 3 pages and i am
trying to skip the onboarding screen when the user has already opened the app once. I have seen something
similar with the shared preferences, but i couldn't make it work.
This is my onboarding screen:
List<Widget> _buildPageIndicator() {
List<Widget> list = [];
for (int i = 0; i < _numPages; i++) {
list.add(i == _currentPage ? _indicator(true) : _indicator(false));
}
return list;
}
You can use SharedPreferences to se a value when the first Screen is see. In the main you can load this value and use it to
decide where to route the user. – Guilherme Dec 9 '19 at 2:35
add a comment
code snippet
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: initScreen == 0 || initScreen == null ? "first" : "/",
routes: {
'/': (context) => MyHomePage(
title: "demo",
),
"first": (context) => OnboardingScreen(),
},
);
}
}
full code
onTap: () => print('Get Started'),
child: Center(
child: Padding(
padding: EdgeInsets.only(bottom: 5.0),
child: Text(
'Get Started',
style: TextStyle(
color: Color(0xFF5B16D0),
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
),
),
)
: Text(''),
);
}
}
chunhunghan answered
18.1k ● 1 ● 19 ● 30 Dec 9 '19 at 2:29
edited
Dec 9 '19 at 2:36
2 Good answer. If he doesn't want to setup a route he can also do... home: initScreen ? OnboardingScreen() :
MyHomePage(), – kent Dec 9 '19 at 2:54
add a comment
Your Answer
Body
Add picture
Log in
OR
Name
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
meta chat tour help blog privacy policy legal contact us full site
2020 Stack Exchange, Inc. user contributions under cc by-sa