ilteoood / flutter_i18n

I18n made easy, for Flutter!
MIT License
217 stars 57 forks source link

Non-fatal Null check operator Exception #176

Closed apastuhov closed 3 years ago

apastuhov commented 3 years ago

Hi, I've got next Non-fatal error in crashlytics:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown Instance of 'ErrorDescription'.
       at SimpleTranslator._decodeFromMap(SimpleTranslator.java:50)
       at SimpleTranslator._translateWithKeyFallback(SimpleTranslator.java:42)
       at SimpleTranslator.translate(SimpleTranslator.java:24)
       at FlutterI18n.translate(FlutterI18n.java:107)
       ...

flutter_i18n: ^0.30.0

Translation file is loaded from network via

NetworkFileTranslationLoader(
      baseUri: Uri.https('website.com', 'i18n/'),
      decodeStrategies: [JsonDecodeStrategy()],
)

According to app logs it seems that app started, but translations were not loaded yet - but app tries to get translation and plugin fails with Null check operator.

Looking into the source code of the plugin I have a feeling that it is related to the next lines of SimpleTranslator:

  String? _decodeFromMap(final String key) {
    final Map<dynamic, dynamic> subMap = calculateSubmap(key)!;
    // ...
  }

  Map<dynamic, dynamic>? calculateSubmap(final String translationKey) {
    // ...

So it cannot assign Map<dynamic, dynamic>? to Map<dynamic, dynamic>. But I am not sure if it is a real root cause of the issue. Also, after translations are loaded from network - everything is working as expected ;)

Thanks!

ilteoood commented 3 years ago

Hi! Are you using the ensureInitialized method to wait the full loading of the widget?

Also, can you give me more detail? For example: if there are particular network conditions, if the translation file is hige...

apastuhov commented 3 years ago

That method is not working for me, data in it is always null. Working in debug mode from laptop under extra stable WiFi. File is not huge. I will provide more logs and code samples in few hours.

ilteoood commented 3 years ago

Ping @apastuhov

ilteoood commented 3 years ago

Closed for inactivity