Reputation: 23
I am seeking for whenever a user swipes right, then it would be gone on other page and in the same page if I again the swipe left it would be return me on a home page (from where I started to swipe right).
For a proper idea I am asking about like Instagram whenever I swipe right it will goes to you message section and in the same page if swipe left it will be return me on the main screen
Upvotes: 0
Views: 1474
Reputation: 3121
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(),
],
),
);
}
}
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.
Upvotes: 1