【发布时间】:2021-06-30 03:11:43
【问题描述】:
请帮助解释为什么有时我的 SnackBar 会显示错误。我不明白问题会在什么情况下出现。我只想指出,即使它显示错误,在应用程序本身中,它也可以正常工作。
这是我的代码:
void showFailedSnackBar(String s) {
SnackBar snackBar = SnackBar(
content: Text(s),
duration: Duration(seconds: 3),
backgroundColor: Theme.of(context).primaryColor,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
这是错误:
E/flutter ( 7879): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
E/flutter ( 7879): Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.
【问题讨论】: