When tap on textfield, app crashes returns homepage

Viewed 91

Hi I get an error when user focus textfield, app crashes and returns to homepage (see clip here https://www.screencast.com/t/yiJkCBsibcoY)

I've had this error for a while now and cannot seem to fix it, sometimes it happens on other textfields. I cannot replicate the issue only sent from users. Anyone experience this with flutter?


  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();
                })),
      ),
    );
  }
1 Answers

I had exactly the same issue and was literally going crazy trying to find the solution. For me the error originated in my usage of the GetX state management library. For me the issue was solved by replacing this:

 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);
                        })));

with:

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);
                        }));

I suggest you have a look at how you are opening the page you are experiencing this issue.

Related