Flutter Getx如何允许重复路由,比如列表页面跳转到详情页面,然后再从详情页面跳转到另一个详情页面
Flutter Getx如何实现列表页面跳转到详情页面,然后再从详情页面跳转到另一个详情页面
在 Flutter 的 GetX 中,你可以通过 Get.toNamed 跳转到同一个路由(比如详情页)多次,只需要设置 preventDuplicates: false
onTap: () {
Get.toNamed(
'/detail',
arguments: {'data': item}, // 传递数据
preventDuplicates: false, // 允许重复路由
);
}
完整代码:
class DetailPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final data = Get.arguments['data']; // 获取传递的参数
return Scaffold(
appBar: AppBar(title: Text('详情页')),
body: Center(
child: Column(
children: [
Text('数据: ${data.toString()}'),
ElevatedButton(
onPressed: () {
// 跳转到新的详情页(传递新数据)
Get.toNamed(
'/detail',
arguments: {'data': '新的数据'},
preventDuplicates: false,
);
},
child: Text('跳转到另一个详情页'),
),
],
),
),
);
}
}
更多关于Flutter Getx如何允许重复路由,比如列表页面跳转到详情页面,然后再从详情页面跳转到另一个详情页面的实战教程也可以访问 https://www.itying.com/category-92-b0.html