0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nitesh Sharma
  • 23
  • 1
  • 5

2 Answers2

1

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(),
        ],
      ),
    );
  }
}
  1. 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.

Ali Qanbari
  • 2,923
  • 1
  • 12
  • 28
  • sir in pagevie we can only perform one action at a time and i havn`t use tabbarview – Nitesh Sharma Sep 02 '20 at 11:20
  • Can you clarify on what you mean “only one action at a time”? How many actions are you trying to accomplish at one time? – lenz Sep 02 '20 at 11:57
0

Try Gestures widget. Look at ‘onHorizontalDrag’

lenz
  • 2,193
  • 17
  • 31