我在扑朔迷离中获得了这段弹出式Dialog()代码https://gist.github.com/axilaris/2b186c7a4073671128e8cacc09dfc384,如果您在底部的某个位置签出了代码
@override
Widget build(BuildContext context) {
return Dialog(
...
showSecondaryButton(BuildContext context) {
...
Navigator.of(context).pop(); <--- here is the problem
无论何时呼叫
Navigator.of(_context).pop();
将导致以下错误
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'findAncestorStateOfType' was called on null.
这看起来像是此NoSuchMethodError: The method 'ancestorStateOfType' was called on null with await and async method的副本,但我尝试了不起作用的解决方案。 (上下文只能设置一次,并且检查装入的变量无效)。
如何解决?到目前为止,它关闭了对话框,但我不希望出现此错误。
更改此:
Navigator.of(context).pop();