There is 2 ways that I can think of to do that:
1.The first and easier way is to use a PageView
:
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp>{
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
children: [
FirstPage(),
SecondPage(),
ThirdPage(),
],
),
);
}
}
- The second way is to use a
TabBarView
:
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin{
@override
Widget build(BuildContext context) {
return Scaffold(
body: TabBarView(
controller: TabController(length: 3, vsync: this),
children: [
FirstPage(),
SecondPage(),
ThirdPage(),
],
),
);
}
}
If you have a tab bar use TabBarView
otherwise PageView
is better in every other way.