Skip to content

L10n.load should return synchronous future, otherwise black frame is shown #90

@orestesgaolin

Description

@orestesgaolin

Currently the implementation of load() function returns Future

  static Future<L10n> load(Locale locale) {
    final name = (locale.countryCode?.isEmpty ?? false)
        ? locale.languageCode
        : locale.toString();
    final localeName = Intl.canonicalizedLocale(name);
    return initializeMessages(localeName).then((_) {
      Intl.defaultLocale = localeName;
      final instance = L10n();
      L10n._current = instance;

      return instance;
    });
  }

However, this causes a black frame to appear just before the MaterialApp renders (e.g. like here, but I see this also in our app when we rebuild MaterialApp).

This is frame by frame view of our app when the MaterialApp is rebuilt:

CleanShot.2022-10-05.at.15.30.33.mp4

It should by default return SynchronousFuture (see example here). I succeeded with something like this:

  static Future<L10n> load(Locale locale) {
    final name = (locale.countryCode?.isEmpty ?? false)
        ? locale.languageCode
        : locale.toString();
    final localeName = Intl.canonicalizedLocale(name);
    initializeMessages(localeName).then((_) {
      Intl.defaultLocale = localeName;
      final instance = L10n();
      L10n._current = instance;

      return instance;
    });

    return SynchronousFuture<L10n>(L10n());
  }

Would you need a reproducible example?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions