The asynchronous startup initialisation of the library enforces the use of preloaderWidget/Color in order to provide a smooth experience to our users.
In order to provide a smooth transition to our users though, we would need to present a widget that is somewhat similar to the widget that is going to be presented after the initialisation ( which is the application's main widget ). The issue here is that this widget will probably have text that cannot be translated because easy_localization is not initialised yet. So the only real option here is to either show a blank color with preloaderColor or a very simple loading widget with preloaderWidget.
My proposal is the following:
// ensureInitialized ensures that the last used locale is loaded from SharedPrefs
// and that the app will have the correct locale from 1st frame.
// Omitting this will result in the app always using the fallbackLocale
await EasyLocalization.ensureInitialized();
This will be called at main before runApp as other libraries like Hive recommend developers to do.
( Keep in mind that as long as we block the execution of runApp the native splash screen is shown which i believe is something expected from the flutter community )
In order to not break the api of the library, i recommend adding ensureInitialized as an option for developers to use, in order to make the library more flexible on this matter.
@aissat
@Overman775 check this
Also the fact that EasyLocalization needs to wrap MaterialApp, makes the use of preloaderWidget even more limited.
You cannot even use Text because Directionality is missing.
And the fact that we cannot use Text inside preloaderWidget is not properly documented on the docs which will surely cause confusion for newcomers.
I would advocate to remove the preloaderWidget completely because it makes the api of the library unnecessarily complicated, but this would require a major version bump.
Maybe start with having both options available and deprecate preloaderWidget/Color on the next major update.
@aissat @spiritinlife Agree. I planned to split into singleton and provader in version 3.0, EasyLocalization EasyLocalizationProvider. This will allow it to be used without context
@spiritinlife Yep, need delete error widged and preloader widger
@Overman775 Can you elaborate on this? what do u mean singleton and provider?
@spiritinlife Put all the logic in the singleton, make it like a service. Make the provider dumb, it will only rebuild the widgets
@Overman775 I see, it is not clear to me how context will not be required though. But i haven't looked at the internals of the lib for some time now. It would be great, If you can prepare a rough PR to discuss.
@spiritinlife @Overman775 I agreed with remove the preloaderWidget coz I don't like it, we added it just to cover Flickering, about another suggestion what about added EasyLocalization loader in same dir like Hive
Check aissat branch
@spiritinlife I will try to find the time
@spiritinlife @aissat and neext step nered finish split like in aissat branch
@aissat I am not sure what we gain from having a second package for loaders to be honest. But its ok i guess.
This is exactly what I expected from this plugin. I used this flow for my localization solution.
Splitting package into singleton and provider should work.
Really looking forward to this!
I thought there was something wrong in my app when I saw that after the splash screen it fades out to a white screen.
To be able to call await EasyLocalization.ensureInitialized(); is the right way do it in my opinion because it will show the native splash screen while EasyLocalization initializes.
The preloaderWidget is indeed unnecessary and makes the package more complicated than it needs to be.
Thank you 馃憤
@Overman775 @aissat do u want me to take a look into this?
@Overman775 @aissat do u want me to take a look into this?
@spiritinlife yep
@spiritinlife yep 馃槂
@Overman775 @aissat https://github.com/aissat/easy_localization/pull/306
Here is my take on it.
There have been a couple of changes that i wasn't aware of, so i cannot take full ownership of this pr. Check the implementation and lets discuss on the pr about it.
Most helpful comment
@Overman775 @aissat https://github.com/aissat/easy_localization/pull/306
Here is my take on it.
There have been a couple of changes that i wasn't aware of, so i cannot take full ownership of this pr. Check the implementation and lets discuss on the pr about it.