flutter_i18n icon indicating copy to clipboard operation
flutter_i18n copied to clipboard

localeResolutionCallback override MaterialApp Locale

Open EArminjon opened this issue 5 years ago • 2 comments

Hello,

I'm facing an issue with the code below :

MaterialApp(
        debugShowCheckedModeBanner: false,
        locale: ui.window.locale, // it is equal to String("fr")
        localizationsDelegates: [
          S.delegate,
        ],
        localeResolutionCallback: S.delegate.resolution(fallback: const Locale('en', '')),
        supportedLocales: S.delegate.supportedLocales,
);

localeResolutionCallback is, as I understand, a callback when no local is found. The problem is the following : localeResolutionCallback is always call and override locale: ui.window.locale...

Can you help me ?

EArminjon avatar Nov 07 '19 07:11 EArminjon

I had the same issue. A bit pointless to provide internationalization if always the same language is used, isn't it? Using the code below fixes it:

MaterialApp(
        debugShowCheckedModeBanner: false,
        localizationsDelegates: [
          S.delegate, GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate
        ],
localeResolutionCallback:
            S.delegate.resolution(fallback: const Locale('en', null)),
        supportedLocales: S.delegate.supportedLocales,
);

Anyways, I keep getting The getter 'MY_ARB_KEY' was called on null. Receiver: null. Tried calling: MY_ARB_KEY frequently, turning the entire plugin is pointless.

jangruenwaldt avatar Jan 04 '20 20:01 jangruenwaldt

Nevermind, translating still sporadically does not work. Also, sometimes the mentioned "called on null" error occurs. I can just suggest everyone to never use this plugin. It is still recommended in some blog posts, but we should make people aware of the issues by leaving 1-star reviews on IntelliJ to make the issues more obvious. It is quite a big waste of time to try using this plugin and will save everyone a headache.

jangruenwaldt avatar Jan 04 '20 21:01 jangruenwaldt