![](/img/trans.png)
[英]How to use Flutter same Page navigation with Getx route or material route?
[英]Flutter navigation to same page
如何在我的 flutter 應用程序中實現功能,我有一個產品詳細信息頁面,在此頁面內我有另一個產品列表,其中包含類似產品。 因此,當我點擊該產品圖塊時,我想推送具有不同產品詳細信息的同一頁面? 我在我的項目中使用 Getx..
例子:
首頁->產品詳情->產品詳情
您可以使用GetX 路由管理中的 arguments 來執行此操作。 不要忘記配置路由以正常工作。
調用路由
ElevatedButton(
onPressed: () => Get.to(const PageOne(), arguments: {
'id': Random().nextInt(1000).toString()
}), // Passing data by using "arguments"
child: const Text('Go to page One'),
),
在將接收參數的頁面上
// Page One
class PageOne extends StatelessWidget {
const PageOne({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Page One'),
),
body: Center(
child: Text(
Get.arguments['id'] ?? 'Page One',
style: const TextStyle(fontSize: 40),
),
),
);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.