首页 > 解决方案 > 如何实现属性向右滑动和向左滑动

问题描述

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

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

标签: flutteruser-interface

解决方案


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

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会更好。


推荐阅读