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

Not compatible with flutter 3.19 #46

Open
zakblacki opened this issue Feb 20, 2024 · 18 comments
Open

Not compatible with flutter 3.19 #46

zakblacki opened this issue Feb 20, 2024 · 18 comments

Comments

@zakblacki
Copy link

zakblacki commented Feb 20, 2024

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
`

@aungzwin10
Copy link

When we can get the update version which fix this issue?

@ClevertonZarelli
Copy link

Following

@moinkhan780
Copy link

@emanuel-braz Please kindly fix this bug.

@Ishaqio
Copy link

Ishaqio commented Feb 25, 2024

when this will be fixed?
are there any other packages that do the same work?

@mohamedsalah414
Copy link

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.

@emanuel-braz
Copy link
Owner

Hello guys, I got a PR #45
I'm gonna check it, and release a new version

@Bakti17
Copy link

Bakti17 commented Feb 27, 2024

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 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

@Pomis
Copy link

Pomis commented Feb 28, 2024

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.

@emanuel-braz
Copy link
Owner

emanuel-braz commented Feb 29, 2024

I need to check this out, because that generic argument was removed in version 4.0.0.

Future<PersistentBottomSheetController?> showBottomSheet<T>({

For now can you run flutter clean and flutter pub get and verify if it still getting error?

@emanuel-braz
Copy link
Owner

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

@Bakti17
Copy link

Bakti17 commented Feb 29, 2024

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?

@duy-ntt
Copy link

duy-ntt commented Feb 29, 2024

@Bakti17
try add OneContext().key = _router.navigatorKey; before declare MaterialApp.router

builder: (context, child) {
    OneContext().key = _router.navigatorKey;
return MediaQuery(

@Bakti17
Copy link

Bakti17 commented Feb 29, 2024

@duy-ntt
i already tried but still have same error

@Bakti17
Copy link

Bakti17 commented Feb 29, 2024

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?

@leornt
Copy link

leornt commented Mar 11, 2024

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;
  }

  ...

@leornt
Copy link

leornt commented Apr 11, 2024

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

Tried to run it today, but bug still persists, any updates on it?

@duy-ntt
Copy link

duy-ntt commented Apr 11, 2024

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(
...
                      );
                    })),
          );
        });
  }

@leornt
Copy link

leornt commented Apr 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests