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

No such method...BuildContextEasyLocalizationExtension.locale #247

Closed
darrinps opened this issue Sep 8, 2020 · 4 comments
Closed

No such method...BuildContextEasyLocalizationExtension.locale #247

darrinps opened this issue Sep 8, 2020 · 4 comments

Comments

@darrinps
Copy link

darrinps commented Sep 8, 2020

When I run the small test program I built using easy_localization I get the following:

The following NoSuchMethodError was thrown building App(dirty):
The getter 'locale' was called on null.
Receiver: null
Tried calling: locale

The relevant error-causing widget was:
App file:///C:/GitProjects/my-test-app/lib/main.dart:66:14

When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 BuildContextEasyLocalizationExtension.locale (package:easy_localization/src/public_ext.dart:88:50)
#2 App.build (package:myapp/main.dart:78:17)
#3 StatelessElement.build (package:flutter/src/widgets/framework.dart:4620:28)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4546:15)
#5 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#6 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
#7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
... Normal element mounting (555 frames)

In the pubspec.yaml file I have:
easy_localization: 2.3.3
easy_localization_loader: 0.0.2

My relevant code is:

`

import 'package:easy_localization_loader/easy_localization_loader.dart';
import 'package:easy_localization/easy_localization.dart';

void run(Environment env, bool enableDebug) {
  runApp(Bootstrap(
    child: Reboot(
      supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')],
      path: 'assets/translations/langs.csv',
      assetLoader: CsvAssetLoader(),
    child: App(),
  ),
  env: env,
  enableDebug: enableDebug,
));
}

class App extends StatelessWidget {
 const App({Key key}) : super(key: key);
@override
 Widget build(BuildContext context) {
log(context.locale.toString(), name: '${this} # locale Context'); // <---CRASHES HERE
log('title'.tr().toString(), name: '${this} # locale');

log('Current locale: ${context.locale.toString()}');

context.locale = Locale('de', 'DE');

log('New locale: ${context.locale.toString()}');

var config = context.use<Config>();`
@Overman775
Copy link
Collaborator

@darrinps show Reboot widget

@darrinps
Copy link
Author

darrinps commented Sep 14, 2020

Here:

      `class Reboot extends StatefulWidget {
       final Widget child;

       Reboot({this.child, List<Locale> supportedLocales, String path, CsvAssetLoader assetLoader});

       @override
        _RebootState createState() => _RebootState();

        static void reboot(BuildContext context) {
             context.findAncestorStateOfType<_RebootState>().restartApp();
        }
     }`

@darrinps
Copy link
Author

Any thoughts?

@bw-flagship
Copy link
Collaborator

Not enough code to reproduce, I suppose we need to see the Reboot-Widget to investigate. Please comment if the issue persists.

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

3 participants