首页 > 解决方案 > 在 Dart 的主线程中强制执行

问题描述

在我的 Dart 程序中,我使用的是相机:

...    
final File imageProduct =  await ImagePicker.pickImage(source: ImageSource.camera, maxHeight: 1024, maxWidth: 1024);
...

之前的版本很好用,现在Flutter升级(v1.7.8+hotfix.3)后显示相机界面,可以拍照了,之后报错:

W/Binder  ( 7331): Caught a RuntimeException from the binder stub implementation.
W/Binder  ( 7331): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Binder:7331_4

在 Flutter 中,异步函数在主线程中执行,所以我真的不明白可能是什么问题。我找不到在主线程中强制执行的明确方法。

可能是什么解决方案。

谢谢。

标签: flutterdart

解决方案


  1. 将颤振频道更改为开发(颤振频道开发)。(你可以省略这一步)
  2. 运行颤振升级
  3. 将 ImagePicker 的版本更改为最新的 0.6.3+1。
  4. 运行项目

问题解决了。


推荐阅读