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

Using Form With PageView Overwrites Previous Form Data With Each Page Flutter

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

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

  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}]

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

您可以为每个字段使用 TextEdittingController