zun zoned error
J-Nokwal opened this issue · 11 comments
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.
binding.dart:497
#1 BindingBase.debugCheckZone
binding.dart:502
#2 runApp
binding.dart:1080
#3 main.
main.dart:40
════════════════════════════════════════════════════════════════════════════════
Future main() => bugsnag.start(
apiKey: 'mykey',
runApp: () async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
await configureDependencies();
// FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
runApp(const MyApp());
},
);
zone mismatched error for this code
The plugin is outdated. They need to update their plugin to meet the new error collection requirement.
Instead of creating a new Zone, PlatformDispatcher must be used for error collection.
Also, don't update Gradle to 8, the plugin is not compatible yet.
Update:
Found a workaround:
In client.dart
file start() function, comment out:
// guarding WidgetsFlutterBinding.ensureInitialized() catches
// async errors within the Flutter app
// _runWithErrorDetection(
// detectDartErrors,
// () => WidgetsFlutterBinding.ensureInitialized(),
// );
Then, in start() function change:
_runWithErrorDetection(detectDartErrors, () => runApp?.call());
to
if (runApp != null) {
_runWithErrorDetection(detectDartErrors, () => runApp?.call());
}
After that, in your main.dart file, init Bugsnag using PlatformDispatcher, something like the below:
await bugsnag.start(apiKey: apiKeyBugSnag);
final errorHandler = bugsnag.errorHandler;
FlutterError.onError = (details) {
FlutterError.presentError(details);
errorHandler(details.exception, details.stack);
};
PlatformDispatcher.instance.onError = (error, stack) {
errorHandler(error, stack);
return true;
};
I did some quick tests, all basic functions are working.
Hi @J-Nokwal,
Thanks for reaching out.
I just wanted to let you know that we are aware of this issue and have an item on our roadmap aimed at replacing these deprecating Zone calls. We don't currently have an ETA for the release of this fix but we will be sure to keep you informed of any updates.
@matth-bugsnag Thanks for the response. I am also running into this issue, while evaluating whether to use bugsnag as a vendor for my team. Any update on a fix ETA?
I happened to be looking at bugsnag as one of the integrations for my team as well. I'm also running into the same issue.
@matth-bugsnag any update on this?
Hi @brokenicedeveloper, we are working on this at present and are hopeful of having an update soon.
@johnkiely1 good luck, let us know when the fix is ready, Best!
@johnkiely1 waiting)))
I encountered a similar issue and was able to find a solution. The problem was caused by multiple zones, and the application needed to run on only one zone. The following code snippet was helpful to me:
Zone.root.runGuarded(() {
runApp(MyApp());
});
Hi all, just a quick update, we have the changes in what we hope is their final stages of testing now. Unless we get any major problems, we hope to release this next week.