pub: https://pub.dev/packages/one_context - OneContext provides a simple way to deal with Dialogs, Overlays and Navigations with no need of BuildContext.
BSD 3-Clause "New" or "Revised" License
80
stars
24
forks
source link
restorationScopeId throws OneContext not initiated exception #52
Hi, i have this simple app that's using restorationScopeId. as i have figure out after hours of debugging that restorationScopeId causes OneContext not initiated exception
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:one_context/src/controllers/one_context.dart': Failed assertion: line 16 pos 12: '_context != null': OneContext not initiated! please use builder method.
You need to use the OneContext().builder function to be able to show dialogs and overlays! e.g. ->
MaterialApp(
builder: OneContext().builder,
...
)
If you already set the OneContext().builder early, maybe you are probably trying to use some methods that will only be available after the first MaterialApp build.
OneContext needs to be initialized by MaterialApp before it can be used in the application. This error exception occurs when OneContext context has not yet loaded and you try to use some method that needs the context, such as the showDialog, dismissSnackBar, showSnackBar, showModalBottomSheet, showBottomSheet or popDialog methods.
If you need to use any of these OneContext methods before defining the MaterialApp, a safe way is to check if the OneContext context has already been initialized.
e.g.
```dart
if (OneContext.hasContext) {OneContext().showDialog (...);}
Hi, i have this simple app that's using
restorationScopeId
. as i have figure out after hours of debugging thatrestorationScopeId
causes OneContext not initiated exceptionFlutter version: 3.19.0
log
0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
2 OneContext.context (package:one_context/src/controllers/one_context.dart:16:12)
3 OneContext.hasContext (package:one_context/src/controllers/one_context.dart:20:46)
4 OneThemeController.loadThemeMode (package:one_context/src/controllers/one_theme_controller.dart:81:20)