Flutter - ModalBottomSheet непредсказуемое поведение - PullRequest
0 голосов
/ 25 февраля 2020

Я нажимаю на карту и открывается нижний лист. Если я нажму на карту и нажму кнопку «Назад» перед созданием нижней таблицы, я получу непредсказуемое поведение (изображение ниже). Как я могу исправить это непредвиденное поведение?

ошибка: поиск предка деактивированного виджета небезопасен. На этом этапе состояние дерева элементов виджета больше не является стабильным. Чтобы безопасно ссылаться на предка виджета в его методе dispose (), сохраните ссылку на предка виджета, вызвав функцию depenOnInheritedWidgetOfExactType () в методе disChangeDependencies () виджета.

Bottom sheet error(unexpectable behaviour)

bottom sheet (Expectable behaviour)

Мой нижний код:

 Future showMainMenu(LatLng _position,BuildContext context) async {
isQueryRowCountEmpty = queries.length > 0 ? false : true;
isFormRowCountEmpty = forms.length > 0 ? false : true;


if (!_modalOpen) {
  _modalOpen = true;

  if (markerPosition == null) {
    selectPositionAlert();
    return null;
  } else {
    if (selectedQueryIndex > -1) {
      //_executeQueryByLocation( context, _position, queries[selectedQueryIndex]);
      return null;
    }
  }

  //TODO localization
  String addressLine = "Adres bulunamadı";

  try {
    var address = await getGeocode(_position);
    addressLine = address.addressLine;
  } on PlatformException {}

  await showModalBottomSheet(
      context: _layerDrawerKey.currentContext,
      backgroundColor: Colors.transparent,
      builder: (context) {
        FocusScope.of(context).requestFocus(new FocusNode());
        return Container(
          height: NetUtils.isTablet(context)
              ? MediaQuery.of(context).size.height / 3
              : MediaQuery.of(context).size.height / 2,
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Container(
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(16.0)),
              child: Padding(
                padding: const EdgeInsets.only(
                    left: 10.0, right: 10.0, bottom: 5.0, top: 5.0),
                child: Column(
                  children: <Widget>[
                    Column(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Padding(
                          padding: const EdgeInsets.all(0.0),
                          child: Text(
                            AL.of(context).trGroup(
                                parent: LC.base_map_screen,
                                child: LC.selected_location),
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                color: Colors.black38),
                          ),
                        ),
                        SizedBox(
                          height: 8,
                        ),
                        Text(
                          addressLine,
                          style: TextStyle(
                              fontWeight: FontWeight.normal,
                              color: Colors.black38),
                          textAlign: TextAlign.center,
                        ),
                        SizedBox(
                          height: 5,
                        )
                      ],
                    ),
                    Visibility(
                      visible:
                          !isQueryRowCountEmpty || !isFormRowCountEmpty,
                      child: Divider(
                        height: 0,
                      ),
                    ),
                    Expanded(
                      child: Visibility(
                        visible:
                            !isQueryRowCountEmpty || !isFormRowCountEmpty,
                        child: Row(
                          mainAxisSize: MainAxisSize.min,
                          children: <Widget>[
                            Visibility(
                              visible: !isQueryRowCountEmpty,
                              child: Expanded(
                                flex: 1,
                                child: Container(
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: <Widget>[
                                        RawMaterialButton(
                                          onPressed: () {
                                            if (queries != null &&
                                                queries.length > 0) {
                                              Navigator.of(context).pop(
                                                  true); //showQueriesMyModalPopup(position);
                                              queryAll();
                                            } else
                                              showToast(
                                                  "Haritada sorgulayabileceğiniz hiç bir katman bulunmuyor.");
                                          },
                                          child: new Icon(
                                            Icons.search,
                                            color: Colors.white,
                                            size: 25.0,
                                          ),
                                          shape: new CircleBorder(),
                                          elevation: 2.0,
                                          fillColor: Colors.deepOrange,
                                          padding:
                                              const EdgeInsets.all(15.0),
                                        ),
                                        Padding(
                                          padding:
                                              const EdgeInsets.fromLTRB(
                                                  0, 8, 0, 0),
                                          child: Text(
                                            AL.of(context).trGroup(
                                                parent: LC.base_map_screen,
                                                child: LC.what_is_here),
                                            style: TextStyle(
                                                fontSize: 12,
                                                color: Colors.grey),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            Visibility(
                              visible: !isFormRowCountEmpty,
                              child: Expanded(
                                flex: 1,
                                child: Container(
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: <Widget>[
                                        RawMaterialButton(
                                          onPressed: () {
                                            if (forms != null &&
                                                forms.length > 0) {
                                              Navigator.of(context).pop(true);
                                              showFormsMyModalPopup(
                                                  _position);
                                            } else
                                              showToast(
                                                  "Harita kayıt ekleyebileceğiniz hiçbir katman bulunmuyor.");
                                          },
                                          child: new Icon(
                                            Icons.add_circle_outline,
                                            color: Colors.white,
                                            size: 25.0,
                                          ),
                                          shape: new CircleBorder(),
                                          elevation: 2.0,
                                          fillColor: Colors.brown,
                                          padding:
                                              const EdgeInsets.all(15.0),
                                        ),
                                        Padding(
                                          padding:
                                              const EdgeInsets.fromLTRB(
                                                  0, 8, 0, 0),
                                          child: Text(
                                            AL.of(context).trGroup(
                                                parent: LC.base_map_screen,
                                                child: LC
                                                    .new_registration_here),
                                            style: TextStyle(
                                                fontSize: 12,
                                                color: Colors.grey),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      flex: (!isQueryRowCountEmpty || !isFormRowCountEmpty)
                          ? 5
                          : 0,
                    ),
                    Divider(
                      height: 0,
                    ),
                    Container(
                        child: ListView.separated(
                            scrollDirection: Axis.vertical,
                            shrinkWrap: true,
                            separatorBuilder:
                                (BuildContext context, int index) =>
                                    Divider(
                                      height: 0,
                                    ),
                            itemCount:
                                mapActions != null ? mapActions.length : 0,
                            itemBuilder: (BuildContext ctx2, int index) {
                              return ListTile(
                                  onTap: () {
                                    if (!_isMapActionRunning)
                                      runMapAction(index, _position);
                                  },
                                  title: Text(mapActions[index].displayName,
                                      style: TextStyle(
                                          color: Theme.of(context)
                                              .primaryColorDark)));
                            })),
                    Icon(
                      Icons.keyboard_arrow_down,
                      color: Colors.grey,
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      });

  Future.delayed(Duration(milliseconds: 1), () => _modalOpen = false);
}
return null;

}

...