Flutter 如何在页面上弹出Navigator.of(context).pop并在flatter上重置它
我有一个产品页面,里面有一些信息。此页面中有一些小部件 问题是当我更改此信息并按下页面顶部的后退按钮时,将执行Navigator.of(context.pop) 当我再次单击以显示页面时,该产品的信息与我以前输入的信息相同 执行Navigator.of(context.pop)时如何重置页面 我的问题是,如果我使用:Flutter 如何在页面上弹出Navigator.of(context).pop并在flatter上重置它,flutter,Flutter,我有一个产品页面,里面有一些信息。此页面中有一些小部件 问题是当我更改此信息并按下页面顶部的后退按钮时,将执行Navigator.of(context.pop) 当我再次单击以显示页面时,该产品的信息与我以前输入的信息相同 执行Navigator.of(context.pop)时如何重置页面 我的问题是,如果我使用: Navigator.of(context).pushReplacementNamed('/Pages', arguments: 0); 但我不想这样,因为每次我做推送替换时,他们
Navigator.of(context).pushReplacementNamed('/Pages', arguments: 0);
但我不想这样,因为每次我做推送替换时,他们都会再次加载以前加载过的页面
这是显示问题的事件序列
首先,我单击网格中产品的图像,这是我执行的操作:
Get.toNamed('/Food', arguments: new RouteArgument(
heroTag: this.widget.heroTag,
param: widget.foodList.elementAt(index),),);
当我更改页面时,我执行此功能:
@override
Widget build(BuildContext context) {
_con.iniPage(this.routeArgument);
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(0.0), // here the desired height
child: AppBar(
automaticallyImplyLeading: false,
brightness: Brightness.dark,
backgroundColor: Colors.transparent,
),
),
此函数\u con.ini页面(此.routeArgument)从参数传递的对象执行克隆事件,功能如下:
iniPage(RouteArgument routeArgument) {
this.routeArgument = new RouteArgument(
heroTag: routeArgument.heroTag,
param: routeArgument.param,);
Food foodTemp = routeArgument.param;
this.food = routeArgument.param.copyAll(food: foodTemp);
calculateTotal();
}
看到我在克隆对象了吗?这是我的克隆功能:
Food copyAll({Food food}) {
return Food(
id: id ?? food.id,
name: name ?? food.name,
price: price ?? food.price,
discountPrice: discountPrice ?? food.discountPrice,
image: image ?? food.image,
description: description ?? food.description,
ingredients: ingredients ?? food.ingredients,
weight: weight ?? food.weight,
unit: unit ?? food.unit,
packageItemsCount: packageItemsCount ?? food.packageItemsCount,
featured: featured ?? food.featured,
deliverable: deliverable ?? food.deliverable,
restaurant: restaurant ?? food.restaurant,
category: category ?? food.category,
extraGroupsFoods: extraGroupsFoods ?? food.extraGroupsFoods,
extraGroupsRules: extraGroupsRules ?? food.extraGroupsRules,
foodReviews: foodReviews ?? food.foodReviews,
nutritions: nutritions ?? food.nutritions
);
}
克隆后,这是我做的第一件事,我的页面在此小部件中循环:
_con.food.extraGroupsFoods != null &&
_con.food.extraGroupsFoods.length > 0
? Column(
children: [
for (var extraGroupFood in _con.food.extraGroupsFoods)
_con.getExtraSelectType(
extraGroupFood,
_con.food.extraGroupsRules),
ExtraObsWidget(_con.getObsText),
],
)
: Container(),
这里的问题是,我在克隆对象上进行了简单的循环,但如果我更改了此特定小部件中的信息,请按“上一步”弹出此屏幕并返回此屏幕,我的信息状态不会重置为什么
当我看到参数对象被修改时,我不知道为什么,因为我从这个对象克隆了一个对象。如果你是说重置第二页,请在弹出前使用Willposcope重置第二页
WillPopScope(
onWillPop: () async {
// your reset logic here
return Future.value(true);
},
child: new Scaffold(
如果您的意思是重置首页,请使用“等待”按钮在返回后重置首页
await Navigator.of(context).pushNamed('/Pages');
// some logic will execute when popping second page
这是重置第二页时,我弹出它,我会尝试你第一个例子好,让我知道如果工作!如果这解决了你的问号问题,答案是否定的,那么我会在我的帖子上添加更多内容