【问题标题】:When tap on textfield, app crashes returns homepage当点击文本字段时,应用程序崩溃返回主页
【发布时间】:2022-09-24 23:16:21
【问题描述】:

嗨,当用户关注文本字段、应用程序崩溃并返回主页时出现错误(请参阅此处的剪辑https://www.screencast.com/t/yiJkCBsibcoY

我已经有一段时间了这个错误并且似乎无法修复它,有时它会发生在其他文本字段上。我无法复制仅从用户发送的问题。任何人都经历过颤振?


  Widget searchBox() {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(25.0),
        border: Border.all(color: Color(0xff0F004E), width: 1.0),
      ),
      child: SimpleAutoCompleteTextField(
        key: keyAuto,
        controller: textController,
        suggestions: suggestions,
        textChanged: (text) => searchProduct = text,
        textSubmitted: (text) {
          loadingBarActive = true;
          _sendAnalyticsEvent(text, \'serach_food_action\');
          searchProduct = text.replaceAll(new RegExp(r\'[^\\w\\s]+\'), \'\');
          print(\'searchProduct RegX $searchProduct\');
          newSearch = true;
          _filterCategories(searchProduct);
          _filterRecipes(searchProduct);

          // reset search values to intial
          usdaItems.clear();
          usda!.clear();
          perPage = perPageIntial;
          present.value = 0;

          loadingBarActive = false;
          selectApi = <int, Widget>{
            0: allProductTab(),
            1: allProductTab(),
            2: allProductTab(),
            3: allProductTab(),
          };

          setState(() {
            _loadUSDAlist = usdaFoodProductList();
            _loadOpenList = openFoodProductList();
          });
        },
        style: TextStyle(
            fontFamily: \'Nunito\', fontSize: 20.0, color: Color(0xff0F004E)),
        decoration: InputDecoration(
            border: InputBorder.none,
            // contentPadding: EdgeInsets.only(top: 14.0),
            hintText: \'Search\',
            hintStyle: TextStyle(
                fontFamily: \'Nunito\', fontSize: 16.0, color: Color(0xff0F004E)),
            prefixIcon: Icon(Icons.search, color: Color(0xff0F004E)),
            suffixIcon: IconButton(
                icon: Icon(Icons.close, color: Color(0xff0F004E)),
                onPressed: () {
                  textController.clear();
                })),
      ),
    );
  }
  • 仅在文本不为空时清除。

标签: flutter


【解决方案1】:

我遇到了完全相同的问题,并且正在疯狂地试图找到解决方案。对我来说,错误源于我对 GetX 状态管理库的使用。对我来说,问题是通过替换这个来解决的:

 Get.to(ReservationDetails(res: Reservation.empty()))
                    ?.then(((value) => setState(() {
                          //Reload the reservations for the new date from the server
                          _taskesFuture =
                              FetchReservation(setStatePublic: _setStatePublic)
                                  .fetchReservation(_selectedDate);
                        })));

和:

Navigator.push(context,
                        MaterialPageRoute(
                            builder: ((context) =>
                                ReservationDetails(res: Reservation.empty()))))
                    .then((value) => setState(() {
                          //Reload the reservations for the new date from the server
                          _taskesFuture =
                              FetchReservation(setStatePublic: _setStatePublic)
                                  .fetchReservation(_selectedDate);
                        }));

我建议你看看你是如何打开你遇到这个问题的页面的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    相关资源
    最近更新 更多