【问题标题】:How can I achieve the property swipe right and swipe left in flutter如何实现属性向右滑动和向左滑动
【发布时间】:2020-12-21 12:49:16
【问题描述】:

每当用户向右滑动时,我都在寻找,如果我再次向左滑动,它将消失在其他页面和同一页面上,它将返回主页(从我开始向右滑动的位置) .

对于一个正确的想法,我在询问 Instagram 之类的问题时,我向右滑动它会转到您的消息部分,如果向左滑动它会在同一页面中返回我在主屏幕上

【问题讨论】:

标签: flutter user-interface


【解决方案1】:

我可以想到两种方法来做到这一点:

1.第一种更简单的方法是使用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. 第二种方法是使用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(),
        ],
      ),
    );
  }
}

如果您有标签栏,请使用TabBarView,否则PageView 在其他所有方面都更好。

【讨论】:

  • 先生,在 pagevie 中,我们一次只能执行一项操作,我没有使用 tabbarview
  • 你能解释一下你的意思是“一次只有一个动作”吗?您打算一次完成多少个操作?
【解决方案2】:

试试Gestures widget。看看‘onHorizo​​ntalDrag’

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 2013-02-17
    • 2015-07-10
    • 1970-01-01
    相关资源
    最近更新 更多