gpt4 book ai didi

dictionary - 将 Form 与 PageView 一起使用会在每个页面 Flutter 时覆盖以前的表单数据

转载 作者:行者123 更新时间:2023-12-03 03:04:27 25 4
gpt4 key购买 nike

我正在使用综合浏览量来显示表单和获取数据。但是,对于每一页,以前的数据都会被覆盖。我不确定为什么。这是我正在做的:

我想从每个页面获取这些信息:

  final Map<String, dynamic> ratingCapsule = {
"prodId": null,
"starRating": null,
"_foodRating": null,
"_drinkRating": null,
"recommend": null
};

页面浏览量:

Expanded(
flex: 2,
child: Form(
key: _userRatingKey,
child: IndexedStack(
index: index,
children: <Widget>[
PageView.builder(
itemBuilder: (context, i) {
return _prodctReview2(context, i);
},
itemCount: currentReview.order.orderDetails.length,
controller: _pageController,
)
],
),
)),

验证器:

  void _submit(srating, effectRating, usageRating, userRecommend) {
final FormState form = _userRatingKey.currentState;
if (form.validate()) {
ratingCapsule['starRating'] = srating;
ratingCapsule['_foodRating'] = effectRating;
ratingCapsule['_drinkRating'] = _drinkRating;
ratingCapsule['recommend'] = userRecommend;
form.save();
print(ratingCapsule['prodId']);
print(ratingCapsule['starRating']);
print(ratingCapsule['_foodrating']);
print(ratingCapsule['_drinkRating']);
print(ratingCapsule['recommend']);
print(ratingCapsule.values);

ratingsList.add(ratingCapsule);
print(ratingsList);

setState(() {
vaildForm = true;
print(ratingCapsule);
});
_clearInput();
ratingCapsule.clear();
nextPage();
} else {
print('Invalid Form');
print(ratingCapsule.values);

print(ratingCapsule);
}
}

在第一页我得到:

[{prodId: 51, starRating: 4.0, _foodRating: 5, _drinkRating: 1, recommend: 1}]

但是在第二页我得到:

[{prodId: 55, starRating: 5.0, _foodRating: 5, _drinkRating: 1, recommend: 1}, {prodId: 55, starRating: 5.0, _foodRating: 5, _drinkRating: 1, recommend: 1}]

用新信息覆盖以前的数据。我该如何阻止它?

最佳答案

您可以为每个字段使用 TextEditingController

关于dictionary - 将 Form 与 PageView 一起使用会在每个页面 Flutter 时覆盖以前的表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60684787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com