flutter - 如何实现属性向右滑动和向左滑动
问题描述
每当用户向右滑动时,我都在寻找,如果我再次向左滑动,它将消失在其他页面和同一页面中,它将返回主页(从我开始向右滑动的位置)。
对于一个正确的想法,每当我向右滑动时,我都会像 Instagram 一样询问它,它会转到您的消息部分,如果向左滑动,它会在同一页面中返回主屏幕
解决方案
我可以想到两种方法来做到这一点:
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(),
],
),
);
}
}
- 第二种方法是使用
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
会更好。
推荐阅读
- cmake - CMake导出使用查找包检索的导入库
- javascript - 成功执行后控制器方法不返回任何响应
- javascript - 在不更改对象结构的情况下格式化嵌套日期
- bash - 当名称是实数时,是否可以对文件进行数字排序?
- angular - Angular App 编译成功,得到错误 my-app did not match any elements,你能指导我有什么问题吗?
- angular - TS2322:类型“产品 [] | null' 不可分配给类型 'Product[]'
- javascript - 使用js单击按钮复制到剪贴板
- python - 如何从导入到组合框的 csv 文件中删除花括号?
- python - 持续时间以秒为单位的滑动窗口
- ios - Flutter IOS,CocoaPods 找不到 pod“Firebase/Analytics”的兼容版本