我注意到我的项目中出现了新的 lint 问题。
长话短说:
我需要在我的自定义类中使用 BuildContext
flutter lint 工具与 aysnc 方法一起使用时并不满意。
例子:
MyCustomClass{
final buildContext context;
const MyCustomClass({required this.context});
myAsyncMethod() async {
await someFuture();
# if (!mounted) return; << has no effect even if i pass state to constructor
Navigator.of(context).pop(); # << example
}
}
Run Code Online (Sandbox Code Playgroud) dart flutter flutter-dependencies flutter-state flutter-build
所以我想知道关闭时使用的命令AlertDialog:
FlatButton(
child: Text('Okay'),
onPressed: () {
Navigator.of(context).pop();
},
),
Run Code Online (Sandbox Code Playgroud)
.of() 到底做了什么?我在 flutter 开发文档中找不到任何内容(可能是因为我缺少正确的搜索词)
谁能解释那里发生了什么?