Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
MIT License
403 stars 118 forks source link

Any way to lazy load the LocalizationDelegate? #41

Closed trietbui85 closed 4 years ago

trietbui85 commented 4 years ago

I follow the guide to configure the flutter_translate:

void main() async
{
  var delegate = await LocalizationDelegate.create(
        fallbackLocale: 'en_US',
        supportedLocales: ['en_US', 'es', 'fa']);

  runApp(LocalizedApp(delegate, MyApp()));
}

It takes about 263ms (debug build, Galaxy S9 Android 10) to create the LocalizationDelegate. Thus, I wonder if you have another way to lazy create it?

For example: let runApp(myApp()) first, then show a loading screen while waiting for creating the LocalizationDelegate. After it's done, then show the next screen.

That idea is borrowed from GetIt > allReady method. I'm not sure if you can apply that into flutter_translate.

Library info:

flutter_translate: ^1.4.0

Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.17763.1098], locale en-US)

Finally, thanks for your great library. I'm using it in all 4 projects. 💯

bratan commented 4 years ago

Hi @anticafe, there is no lazy loading functionality currently. The delay is caused by the initial access to the asset files. In debug mode is a bit slower but in release mode the delay should only be ~5ms.

I suggest showing a splash screen while waiting for the app to load.

https://flutter.dev/docs/development/ui/splash-screen/android-splash-screen

trietbui85 commented 4 years ago

release mode the delay should only be ~5ms

It sounds good, less than a frame (16.67ms), thus no one will notice that.