ilteoood/flutter_i18n

_CastError Null check operator used on a null value

daninfpj opened this issue · 5 comments

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.

Can you provide a minimal reproduction example?

tomk9 commented

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

tomk9 commented

@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?

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

A fix should have been published with version 0.32.3