A flutter test app to investigate a black screen problem on Stack overflow
To reproduce the problem situatioon, use flutter run
to run this app then modity below initialization code in /lib/app.dart
return MaterialApp(
localizationsDelegates: [
S.delegate, // <--- will cause black screen
//AppLocalizations.delegate, // <--- no black screen
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
...
Apply the flutter_intl to enable the app internationalize. It generates class S with asynchronous future call inside will cause an instantaneous black screen at program start.
static Future<S> 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 = S();
S._current = instance;
return instance;
});
}
Follow the internationalize guidance on official flutter.dev generate very similar class _AppLocalizationsDelegate, which is also override the load method as below.
Future<AppLocalizations> load(Locale locale) {
return SynchronousFuture<AppLocalizations>(_lookupAppLocalizations(locale));
}