Флаттер удаляет диалоги последовательно - PullRequest
0 голосов
/ 16 ноября 2018

Я пытаюсь удалить диалоги в определенной последовательности, но получаю следующую ошибку:

E/flutter (14457): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error: Unhandled exception:
E/flutter (14457): Looking up a deactivated widget's ancestor is unsafe.
E/flutter (14457): At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.

Вот последовательность:

  1. Элемент списка
  2. Открыть диалог подтверждения 1
  3. Закрыть (onPressed) диалог 1
  4. Открыть диалог загрузки 2.
  5. Закрыть (Navigator.of (context) .pop ())
  6. Открыть диалоговое окно 3 с сообщением об успехе.

Оба диалоговых окна 1 и 2 закрыты с помощью Navigator.of (context) .pop ().

Как это исправить?

1 Ответ

0 голосов
/ 17 апреля 2019

Когда вы используете функцию Navigator.of(context).pop(), не используйте контекст из предыдущего диалога, попробуйте использовать контекст страницы。 Причина Looking up a deactivated widget's ancestor is unsafe в том, что предыдущий диалог закрыт, но вы используете контекст этого диалога. Вы можете увидеть исходный код:

static NavigatorState of(
    BuildContext context, {
      bool rootNavigator = false,
      bool nullOk = false,
    }) {
    final NavigatorState navigator = rootNavigator
        ? context.rootAncestorStateOfType(const TypeMatcher<NavigatorState>())
        : context.ancestorStateOfType(const TypeMatcher<NavigatorState>());// here check the ancestor state,and throw the error
    assert(() {
      if (navigator == null && !nullOk) {
        throw FlutterError(
          'Navigator operation requested with a context that does not include a Navigator.\n'
          'The context used to push or pop routes from the Navigator must be that of a '
          'widget that is a descendant of a Navigator widget.'
        );
      }
      return true;
    }());
    return navigator;
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...