相关疑难解决方法(0)

不要跨异步间隙使用 BuildContext

我注意到我的项目中出现了新的 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

240
推荐指数
7
解决办法
16万
查看次数