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

Null check operator used on a null value #533

Closed
divineaseaku opened this issue Nov 8, 2022 · 12 comments
Closed

Null check operator used on a null value #533

divineaseaku opened this issue Nov 8, 2022 · 12 comments
Labels
waiting for customer response Waiting for customer response

Comments

@divineaseaku
Copy link

Setup easy_localization: 3.0.1 as in example on package but got error Null check operator used on a null value upon running the app.

My IDE points the error to line 48 EasyLocalization.of(this)!.delegates; on on file easy_localization/src/public_ext.dart.

@alireza-rajaei
Copy link

i have the same issue inside testWidgets

          debugShowCheckedModeBanner: false,
          localizationsDelegates: context.localizationDelegates,
          supportedLocales: context.supportedLocales,

The following _CastError was thrown building Builder(dirty):
Null check operator used on a null value

@khayargoli
Copy link

Same with me

@Syed95github
Copy link

localizationsDelegates: context.localizationDelegates,
this is causing the error.
Any one solved this ?

@DirtyNative
Copy link

Same problem here. Did anyone find a solution?

@Mar1anne
Copy link

Same here. Any updates?

@mohkoma
Copy link

mohkoma commented Feb 1, 2023

This is mostly because the parent widget still not fully initialized, Which means the context still doesn't have localizationDelegates or supportedLocales.
The easy way to solve this is to wrap your MaterialApp, CupertinoApp or WidgetsApp inside a builder.
Something like this:

EasyLocalization(
      supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')],
      path: 'assets/translations',
      fallbackLocale: Locale('en', 'US'),
      child: builder(
          builder: (context) {
               return MaterialApp(
                  localizationsDelegates: context.localizationDelegates,
                  supportedLocales: context.supportedLocales,
                  locale: context.locale,
                  home: MyHomePage()
               )
          }
      )
 ),

@Mar1anne
Copy link

Mar1anne commented Feb 6, 2023

@mohkoma I had the same implementation as you mentioned.

If I have the following setup:
Project A -> app with easy localization
Project B -> app with a dependency of Project A.
I always get the same error in Project B.

@mohkoma
Copy link

mohkoma commented Feb 6, 2023

@Mar1anne It's hard for me to find the issue without seeing the code, but I assume that the Project B still doesn't have the context that has a loaded easy localisation. Therefore, try to wrap the Project B inside another builder also?

@Mar1anne
Copy link

@mohkoma Maybe, I guess that should work. I changed my implementation since then, but I'll test this out as soon as I got the time. Thanks!

@bw-flagship
Copy link
Collaborator

Several people seem to have this issue, could someone post a sample to reproduce? I don't think we have a bug here, but maybe something the docs should cover.

@bw-flagship bw-flagship added the waiting for customer response Waiting for customer response label May 13, 2023
@SwiftSpotter
Copy link

@mohkoma ur solution fixed it for me thanks.

@bw-flagship
Copy link
Collaborator

Closing since the solution seems to work. Thanks @mohkoma

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

No branches or pull requests

9 participants