上下文:
这是我的主要要点和起点,从不必要的线条中剔出到Q:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
onGenerateTitle: (BuildContext context) => 'MyTitle',
localizationsDelegates: [
const CopyDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''),
const Locale('bg', ''),
],
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => Init(),
},
);
}
}
这是CopyDelegates类:
class CopyDelegate extends LocalizationsDelegate<Copy> {
const CopyDelegate();
//TODO change the source of supported languages
@override
bool isSupported(Locale locale) => ['en', 'bg'].contains(locale.languageCode);
@override
Future<Copy> load(Locale locale) async{
Copy copy = Copy(locale);
copy.load();
return copy;
}
@override
bool shouldReload(CopyDelegate old) => false;
}
Copy是一个不继承的简单类,在copy.load()
方法中,我有逻辑可以远程获取本地化信息。这是一个async
函数,带有很多“ await”语句,这些语句进入远程配置,获取复制URL,然后从Firestore下载并将其解析为JSON字符串,并加载到Map中。 Copy
然后提供检索加载的字符串的方法。
最后,这是剥离了其他内容的“ Init”小部件:
class Init extends StatelessWidget {
@override
Widget build(BuildContext context) {
//TODO add logic to transition away from spinner when copy has loaded
return CircularProgressIndicator();
}
}
我遇到的主要问题是: