我正在使用网页浏览来显示表单并获取数据。但是,对于每一页,先前的数据都会被覆盖。我不确定为什么。这是我正在做的事情:
我想从每一页获取这些信息:
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}]
用新信息覆盖以前的数据。我该如何阻止这个?