代码之家  ›  专栏  ›  技术社区  ›  Doing Things Occasionally

将窗体与页面视图一起使用时,每次页面抖动都会覆盖以前的窗体数据

  •  0
  • Doing Things Occasionally  · 技术社区  · 4 年前

    我正在使用页面视图显示表单并获取数据。但是,每一页都会覆盖以前的数据。我不知道为什么。我在做的是:

    我想从每页上得到这些信息:

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

    用新信息覆盖以前的数据。我该怎么阻止?

    0 回复  |  直到 4 年前