Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zone mismatch error on Flutter web with Flutter v3.22.0 #2079

Closed
aprizzo opened this issue May 30, 2024 · 1 comment
Closed

Zone mismatch error on Flutter web with Flutter v3.22.0 #2079

aprizzo opened this issue May 30, 2024 · 1 comment

Comments

@aprizzo
Copy link

aprizzo commented May 30, 2024

Platform

Flutter Web

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.22.0, on macOS 14.5 23F79 darwin-arm64, locale
    it-IT)
    • Flutter version 3.22.0 on channel stable at
      /Users/andrearizzo/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5dcb86f68f (3 settimane fa), 2024-05-09 07:39:20 -0500
    • Engine revision f6344b75dc
    • Dart version 3.4.0
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/andrearizzo/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_SDK_ROOT = /Users/andrearizzo/Library/Android/sdk/
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.88.0

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Version

8.2.0

Steps to Reproduce

I'm just trying to launch my Flutter web application with this minimum settings, but I receive the zone mismatch error. I have tried removing the runZonedGuarded, I have tried using it (since on the Sentry documentation it says I should use it with Flutter prior to 3.3, but nothing seems to work. I have written emails to support@sentry.io, and after a few emails they suggested me to open a github issue.

Launching with: flutter run -d Chrome

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:repod/app/app.dart';
import 'package:repod/app/localizations/app_localizations.dart';
import 'package:repod/app/libs/sentry.lib.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> main() async {
  runZonedGuarded(() async {
    WidgetsFlutterBinding.ensureInitialized();
    await SentryFlutter.init(
      (options) {
        options.dsn = SentryLib.shared.sentryDsn;
        options.release = AppLocalizations.instance.translate('AppName');
        options.attachScreenshot = true;
        options.enableAutoPerformanceTracing;
        options.tracesSampleRate = 1.0;
        options.useFlutterBreadcrumbTracking();
      },
      appRunner: () => runApp(SentryScreenshotWidget(child: App())),
    );
  }, (error, stackTrace) {
    print("error $error \n stacktrace $stackTrace");
    return;
  });
}

If I run the above code on Android or iOS, everything works fine and I receive error logs to Sentry as expected.

Update: I have tried to remove the WidgetsFlutterBinding.ensureInitialized() when using Flutter web, but then it doesn't log errors to Sentry anymore.

Expected Result

I expect the app to launch without errors

Actual Result

══╡ 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() { }`).

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 843:28  get current
packages/flutter/src/foundation/binding.dart 495:29                 <fn>
packages/flutter/src/foundation/binding.dart 499:14                 debugCheckZone
packages/flutter/src/widgets/binding.dart 1439:17                   _runWidget
packages/flutter/src/widgets/binding.dart 1373:3                    runApp
packages/repod/main.dart 18:22                                      <fn>
packages/sentry/src/sentry.dart 137:26                              <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50  <fn>
dart-sdk/lib/async/zone.dart 1407:47                                _rootRunUnary
dart-sdk/lib/async/zone.dart 1308:19                                runUnary
dart-sdk/lib/async/future_impl.dart 163:18                          handleValue
dart-sdk/lib/async/future_impl.dart 847:44                          handleValueCallback
dart-sdk/lib/async/future_impl.dart 876:13                          _propagateToListeners
dart-sdk/lib/async/future_impl.dart 652:5                           [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 722:7                           <fn>
dart-sdk/lib/async/zone.dart 1399:13                                _rootRun
dart-sdk/lib/async/zone.dart 1301:19                                run
dart-sdk/lib/async/zone.dart 1209:7                                 runGuarded
dart-sdk/lib/async/zone.dart 1249:23                                callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                    _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                     _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7  <fn>
════════════════════════════════════════════════════════════════════════════════════════════════════

Are you willing to submit a PR?

No

@buenaflor
Copy link
Contributor

Closing this as a duplicate of #2063

please raise your concerns in that thread if you still have any

@buenaflor buenaflor closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

No branches or pull requests

3 participants