ilteoood / flutter_i18n

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

_CastError Null check operator used on a null value #193

Closed daninfpj closed 2 years ago

daninfpj commented 2 years ago

I’m sometimes getting this error when calling translate.

The problem lies within this function:

  Map<dynamic, dynamic>? calculateSubmap(final String translationKey) {
    final List<String> translationKeySplitted =
        translationKey.split(this.keySeparator!);
    translationKeySplitted.removeLast();
    Map<dynamic, dynamic>? decodedSubMap = decodedMap;
    translationKeySplitted.forEach((listKey) =>
        decodedSubMap = (decodedSubMap ?? Map())[listKey] ?? Map());
    return decodedSubMap;
  }

Specifically, when reaching this line:

Map<dynamic, dynamic>? decodedSubMap = decodedMap;

decodedMap is null, which makes the function return null.

Then, on this line the null check fails:

final Map<dynamic, dynamic> subMap = calculateSubmap(key)!;

Why would decodedMap be null at that point? In my app, on a following repaint it is no longer null.

ilteoood commented 2 years ago

Can you provide a minimal reproduction example?

tomk9 commented 2 years ago

Error is when key is "" in _decodeFromMap. I paste stacktrace. image image image image image

tomk9 commented 2 years ago

@daninfpj could you test the fix?

  flutter_i18n:
    git: https://github.com/ilteoood/flutter_i18n

It helped me. Maybe after @daninfpj confirmation, @ilteoood could release a new version on pub and close the issue?

ilteoood commented 2 years ago

Hi guys, I'm in honeymoon right now. The suggested workaround could be used until I come back, at the end of this week.

ilteoood commented 2 years ago

A fix should have been published with version 0.32.3