Flutter Dialog Context 注意事项
在这个例子中,显示调用 AlertDialog,假设按了确定,则弹出一个 LoadingDialog 访问 api。在这个过程中,LoadingDialog 还可以正常展示,但是无法隐藏,此时 context 为空。因为 Navigator.pop(context, ‘OK’) 已经把 AlertDialog 出栈,其对应的 context 也会 unmounted。
在这个例子中,显示调用 AlertDialog,假设按了确定,则弹出一个 LoadingDialog 访问 api。在这个过程中,LoadingDialog 还可以正常展示,但是无法隐藏,此时 context 为空。因为 Navigator.pop(context, ‘OK’) 已经把 AlertDialog 出栈,其对应的 context 也会 unmounted。