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

NoSuchMethodError:The method ‘[]’ was called on null. #31

Closed
qiaoshouqing opened this issue Apr 21, 2019 · 11 comments
Closed

NoSuchMethodError:The method ‘[]’ was called on null. #31

qiaoshouqing opened this issue Apr 21, 2019 · 11 comments

Comments

@qiaoshouqing
Copy link

I found that there were two things that would happen.

  1. Ios system, zh Chinese. An error will be reported after killing the process and restart the application to translate the first string.
  2. Occasionally. Problems can occur when switching to another page. And when you get back, the entire application will be in trouble.

Can it be solved in time?

NoSuchMethodError:The method ‘[]’ was called on null.
Receiver:null
Tried calling:[](“motto”)
@qiaoshouqing
Copy link
Author

qiaoshouqing commented Apr 21, 2019

Using the latest version 0.6.3

@ilteoood
Copy link
Owner

Hi,
Without any code example is hard for me to replicate it.

@qiaoshouqing
Copy link
Author

I submitted the error log. Can't the error log?

@ilteoood
Copy link
Owner

I need an example of:

  • how you initialize it
  • how you use it
  • how you structured the assets folder

@ilteoood
Copy link
Owner

Also, did you set a fallback file?

I think that this problem is similar to #23.

@qiaoshouqing
Copy link
Author

init

    localizationsDelegates: [
        FlutterI18nDelegate(
          useCountryCode: false,
          fallbackFile: "zh",
          path: "assets/flutter_i18n"
        ),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],

use

In order to deal with the first error situation.

import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';

class LocalizationUtil {

  static String translate(BuildContext context, var key, [final Map<String, String> translationParams]) {
    try {
      return FlutterI18n.translate(context, key, translationParams);
    } catch(e) {
      print("FlutterI18n Exception:" + e.toString());
      return key;
    }
  }

}
LocalizationUtil.translate(context, "motto"),

file struct

- assets/flutter_i18n/
- assets/flutter_i18n/en.json
- assets/flutter_i18n/zh.json

@ilteoood
Copy link
Owner

Seems everything fine.
Can you tell me the output of the

  • Localizations.localeOf
  • FlutterI18N.currentLocale

methods?

@qiaoshouqing
Copy link
Author

In Chinese.
flutter: Localizations.localeOf(context):en_US
flutter: FlutterI18n.currentLocale:zh_CN

Repository owner deleted a comment from theRealBitcoinClub Jun 5, 2019
@ilteoood
Copy link
Owner

ilteoood commented Sep 9, 2019

Hi,
is it happening even with version 0.6.4?
Now with a MBP, I can test it even on iOS :)

@Shakle
Copy link

Shakle commented Nov 4, 2019

I tried to use to use localeResolutionCallback to autodetect language on first launch, but it works only on android, ios has an error described in this issue. Generally it returns deviceLocale = null; And I also did not understand what for does it need a return Locale here.

localeResolutionCallback: (deviceLocale, supportedLocales) {
        if (Database.initialApplicationLanguage == null && Platform.isAndroid) {
            Database.initialApplicationLanguage = Locale(deviceLocale.languageCode);
            Future.delayed(Duration.zero,
                    () => Language.provider(context).locale = Database.initialApplicationLanguage);
        }
        return deviceLocale;
      },

@ilteoood
Copy link
Owner

I'm closing it for inactivity.
For iOS related problems on automatic locale resolution, please use #58

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