Skip to content

关于Zone mismatch解决方法 #162

Open

Description

@crazecoder

出现如下报错时

════════ Exception caught by Flutter framework ════════════════════════════════════
The following assertion was thrown during runApp:
Zone mismatch.

The Flutter bindings were initialized in a different zone than is now being used.
This will likely cause confusion and bugs as any zone-specific configuration will
inconsistently use the configuration of the original binding initialization zone or
this zone based on hard-to-predict factors such as which zone was active when a
particular callback was set.
It is important to use the same zone when calling `ensureInitialized` on the
binding as when calling `runApp` later.
To make this warning fatal, set BindingBase.debugZoneErrorsAreFatal to true before
the bindings are initialized (i.e. as the first statement in `void main() { }`).
[...]
═══════════════════════════════════════════════════════════════════════════════════

使用下面方法解决

void main(){
    runZonedGuarded(() {
      WidgetsFlutterBinding.ensureInitialized();
      runApp(MyApp());
    }, (exception, stackTrace) {
      FlutterBugly.uploadException(
        type: exception.runtimeType.toString(),
        message: exception.toString(),
        detail: stackTrace.toString(),
      );
    });
}

Activity

  1. pinned this issue on Aug 29, 2024
  2. wxc64970 commented on Oct 31, 2024

    @wxc64970

    解决方法里还需要这一句吗?
    FlutterBugly.init(
    androidAppId: "your android app id",
    iOSAppId: "your iOS app id",
    );

  3. crazecoder commented on Oct 31, 2024

    @crazecoder
    OwnerAuthor

    这个是必须的

  4. wxc64970 commented on Oct 31, 2024

    @wxc64970

    这个是必须的

    初始化写在哪个位置

  5. crazecoder commented on Oct 31, 2024

    @crazecoder
    OwnerAuthor

    这个是必须的

    初始化写在哪个位置

    按需选择,个人一般放在启动app时,或者启动后的第一个界面(当然你得有信心,否则第一个界面出来之前的报错不会上传)

  6. wxc64970 commented on Oct 31, 2024

    @wxc64970

    这个是必须的

    初始化写在哪个位置

    按需选择,个人一般放在启动app时,或者启动后的第一个界面

    初始化位置会不会影响隐私协议,还是必须要用户同意隐私协议后才能初始化

  7. crazecoder commented on Oct 31, 2024

    @crazecoder
    OwnerAuthor

    这个是必须的

    初始化写在哪个位置

    按需选择,个人一般放在启动app时,或者启动后的第一个界面

    初始化位置会不会影响隐私协议,还是必须要用户同意隐私协议后才能初始化

    看各市场审核要求,经测google play没有这个要求

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions