我已经有以下应用程序:
class MyAppState extends State<MyApp>
{
TenderApiProvider _tenderApiProvider = TenderApiProvider();
Future init() async {
await _tenderApiProvider.getToken();
}
MyAppState()
{
init();
}
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(builder: (_) => _tenderApiProvider),
],
child: MaterialApp(
title: "My App",
routes: {
'/': (context) => HomePage(),
'/splash-screen': (context) => SplashScreen(),
'/result_table': (context) => ResultDataTable(),
}
),
);
}
}
我需要首先绘制SplashScreen
,当前代码在启动HomePage
时显示。
在闪屏界面中,当所有数据都加载完成后,我需要切换到HomePage
。以下是代码:
Widget build(BuildContext context) {
TenderApiProvider apiProv = Provider.of<TenderApiProvider>(context);
return StreamBuilder(
stream: apiProv.resultController,
builder: (BuildContext context, AsyncSnapshot snapshot) {
//...
if(apiProv.apiKeyLoadingState == ApiKeyLoadingState.Done && apiProv.regionsLoadingState == RegionsLoadingState.Done)
{
Navigator.of(context).pushNamed("/"); // Should it be placed in Build??
}
});
}
你能帮我并展示如何在应用程序启动时绘制SplashScreen
,然后从中切换到HomePage
吗?
能否协助我在应用程序启动时绘制SplashScreen
,并在此后切换至HomePage
?