one_context
one_context copied to clipboard
Not compatible with flutter 3.19
We need update I tried to build with latest flutter I'm getting the following error : (Note: I have tried both Latest and Prerelease version)
my environment: sdk: ">=2.14.4 <3.0.0"
JDK : 17.0.10 Kotlin : 1.9.22 gradle : 8.6 com.android.application : 8.2.2**
`../../AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/one_context-2.1.0/lib/src/controllers/one_context.dart:92:5: Error: Expected 0 type arguments.
PersistentBottomSheetController<T> Function<T>({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/one_context-2.1.0/lib/src/components/one_context_widget.dart:112:3: Error: Expected 0 type arguments.
PersistentBottomSheetController<T> _showBottomSheet<T>({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/one_context-2.1.0/lib/src/controllers/dialog_controller.mixin.dart:70:3: Error: Expected 0 type arguments.
PersistentBottomSheetController<T> Function<T>({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/one_context-2.1.0/lib/src/controllers/dialog_controller.mixin.dart:189:10: Error: Expected 0 type arguments.
Future<PersistentBottomSheetController<T>?> showBottomSheet<T>({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/one_context-2.1.0/lib/src/controllers/dialog_controller.mixin.dart:245:7: Error: Expected 0 type arguments.
PersistentBottomSheetController<T> Function<T>({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/one_context-2.1.0/lib/src/components/one_context_widget.dart:122:12: Error: Expected 0 type arguments.
return showBottomSheet<T>(
^
../../flutter/packages/flutter/lib/src/material/bottom_sheet.dart:1327:33: Context: Found this candidate, but the arguments don't match.
PersistentBottomSheetController showBottomSheet({
^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\zakbl\flutter\bin\flutter.bat'' finished with non-zero exit value 1
`
When we can get the update version which fix this issue?
Following
@emanuel-braz Please kindly fix this bug.
when this will be fixed? are there any other packages that do the same work?
I encountered the same error when deploying a new app bundle using flutter build appbundle --release
. I'm using one_context
version 3.0.0-rc-1 in my project.
Hello guys, I got a PR https://github.com/emanuel-braz/one_context/pull/45 I'm gonna check it, and release a new version
i got same issue using flutter version 3.19.1
/AppData/Local/Pub/Cache/git/one_context-b4e7187f8fccb616ff75c60957dcaf3fad43826a/lib/src/controllers/dialog_controller.mixin.dart:164:10: Error: Expected 0 type arguments. Future<PersistentBottomSheetController<T>?> showBottomSheet<T>({ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Target kernel_snapshot failed: Exception
i tried to modify the targeted function like removing the <T> but then i got error but i already defined one_context on MaterialApp
` 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.
if (OneContext.hasContext) {OneContext().showDialog (...);}
`
Any help with this problem? Thanks
I'm having a similar problem as in the comment above: it started when I've upgraded Flutter from 3.16 to 3.19 and one_context to 4.0.0 Feels like it's crashing when the builder is created. No other calls to OneContext during initialisation are happening.
I need to check this out, because that generic argument was removed in version 4.0.0. https://github.com/emanuel-braz/one_context/blob/5c2869512a759eb4a00eb370d3ccefed80c383cd/lib/src/controllers/dialog_controller.mixin.dart#L164
For now can you run flutter clean
and flutter pub get
and verify if it still getting error?
I have tested it, and the example project is working well, probably there is some cache. If flutter clean
doesn't fix it, please try to run flutter pub cache repair
so i use auto route for my project and it use MaterialApp.router() instead of MaterialApp my code is looking like this
`import 'package:auto_route/auto_route.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:layanan_online/extras/extras.dart'; import 'package:layanan_online/route/routes.dart'; import 'package:one_context/one_context.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
void main() async { //init screenutil await ScreenUtil.ensureScreenSize();
//init firebase instance await Firebase.initializeApp();
WidgetsFlutterBinding.ensureInitialized();
runApp(ProviderScope(child: MyApp())); }
class MyApp extends StatelessWidget { final _router = AppRouter();
MyApp({super.key});
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(360, 800),
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context)
.copyWith(textScaler: const TextScaler.linear(1.0)),
child: MaterialApp.router(
builder:OneContext().builder,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('id'),
Locale('en'),
],
locale: const Locale('id'),
// routerConfig: _router.config(),
routeInformationParser: _router.defaultRouteParser(),
routeInformationProvider: _router.routeInfoProvider(),
routerDelegate: _router.delegate(
deepLinkBuilder: (deepLink) =>
FirebaseAuth.instance.currentUser == null
? const DeepLink([LoginRoute()])
: const DeepLink([MainRoute()])
),
theme: lightTheme,
),
);
});
}
}`
is using auto_route make one context error because using MaterialApp.router instead MaterialApp?
@Bakti17
try add OneContext().key = _router.navigatorKey;
before declare MaterialApp.router
builder: (context, child) {
OneContext().key = _router.navigatorKey;
return MediaQuery(
@duy-ntt i already tried but still have same error
I figure it the problem is when you define MaterialApp that wrapped by builder from another package it will cause an error
OneContext not initiated
maybe you can add some fix for this problem?
NOTE: Assert is there for a reason, removing it is just a temporary dev solution The "fix" that worked for me is removing the assert in "one_context.dart" constructor, just like that:
class OneContext with NavigatorController, OverlayController, DialogController {
static BuildContext? _context;
/// The almost top root context of the app,
/// use it carefully or don't use it directly!
BuildContext? get context {
_context = key.currentContext;
return _context;
}
...
I have tested it, and the example project is working well, probably there is some cache. If
flutter clean
doesn't fix it, please try to runflutter pub cache repair
Tried to run it today, but bug still persists, any updates on it?
Have you tried OneContextWidget?
Widget build(BuildContext context) {
...
return OneNotification<OneThemeChangerEvent>(
stopBubbling: true,
builder: (context, data) {
OneContext().key = router.configuration.navigatorKey;
return MediaQuery(
data: MediaQuery.of(context).scale(),
child: Sizer(
builder: (context, orientation, deviceType) => MaterialApp.router(
...
builder: (context, child) {
return OneContextWidget(
...
);
})),
);
});
}
Have you tried OneContextWidget?
Tried with OneNotification, OneContext().key, and OneContextWidget, none working, same message
Failed assertion: line 16 pos 12: '_context != null': OneContext not initiated! please use builder method
Edit:
Calling OneContext().key
in main() first lines solves the problem, probably something is using before the builder