flutter导航器弹出对话框-错误-未处理的异常:NoSuchMethodError:方法'findAncestorStateOfType'在null上调用

问题描述 投票:0回答:1

我在扑朔迷离中获得了这段弹出式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的副本,但我尝试了不起作用的解决方案。 (上下文只能设置一次,并且检查装入的变量无效)。

如何解决?到目前为止,它关闭了对话框,但我不希望出现此错误。

flutter dialog navigator dismiss
1个回答
0
投票

更改此:

Navigator.of(context).pop();
© www.soinside.com 2019 - 2024. All rights reserved.