1

I recently upgraded my flutter and the following message started to appear:

======== 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: 
#0      BindingBase.debugCheckZone.<anonymous closure> (package:flutter/src/foundation/binding.dart:497:29)
#1      BindingBase.debugCheckZone (package:flutter/src/foundation/binding.dart:502:6)
#2      runApp (package:flutter/src/widgets/binding.dart:1080:18)
#3      mainCommon.<anonymous closure> (package:cashpak_mobile/main_common.dart:20:5)
#8      mainCommon (package:cashpak_mobile/main_common.dart:19:3)
<asynchronous suspension>
(elided 4 frames from dart:async)

this would be my class:

Future<void> mainCommon(AppSettings appSettings) async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  runZonedGuarded(() {
    runApp(
      ProviderScope(
        overrides: [
          flavorConfigProvider.overrideWithValue(appSettings),
        ],
        child: DevicePreview(
          enabled: appSettings.isDev,
          builder: (context) => const MyApp(),
        ),
      ),
    );
  }, (error, stackTrace) {
    FirebaseCrashlytics.instance.recordError(error, stackTrace);
  });
}

Eliminate the Zone mismatch error in the application

1 Answers1

0

The same happened to me.

It seems that 'runZoned' and 'runZonedGuarded' are deprecated now. You need to remove it and use something else. In my case there was an info hint telling me to use Bloc.observer/Bloc.transformer instead.

I first defined Bloc.observer = SimpleBlocObserver() (which is an extended BlocObserver) first and afterwards used "runApp()".

This thread could also help you:

Info: 'runZoned' is deprecated and shouldn't be used. This will be removed in v9.0.0. Use Bloc.Bloc.transformer instead

Colibri
  • 713
  • 12
  • 16