[英]How can I achieve the property swipe right and swipe left in 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
在其他方面都更好。
試試手勢小部件。 看看'onHorizontalDrag'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.