在主屏幕中使用动画容器时,有没有其他方法可以在启动屏幕通过后移动到主屏幕



我在主屏幕中使用了一个动画容器,现在我正试图创建一个防溅屏,但我发现很难返回由动画容器组成的主屏幕,这会在我的防溅屏通过后立即在我的应用程序上出错。在主屏幕中使用动画容器时,有没有其他方法可以在启动屏幕通过后移动到主屏幕?

Widget build(BuildContext context) {
return FutureBuilder(
// Replace the 3 second delay with your initialization code:
future: Future.delayed(Duration(seconds: 3)),
builder: (context, AsyncSnapshot snapshot) {
// Show splash screen while waiting for app resources to load:
if (snapshot.connectionState == ConnectionState.waiting) {
return MaterialApp(home: Splash());
} else {
return AnimatedContainer(child: HomeScreen());
}
},
);
}

您需要将MaterialApp设置为FutureBuilder:的父级

Widget build(BuildContext context) {
// Add a material app in the top-level
return MaterialApp(
home: FutureBuilder(
future: Future.delayed(Duration(seconds: 3)),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
// Remove this material app from here since there's
// already one in the top of the widget tree
return Splash();
} else {
return AnimatedContainer(child: HomeScreen());
}
},
)
);
}

只需返回窗口小部件构建方法中的启动屏幕

在widgets init方法中使用Future.delayed(持续时间(秒:3((.then((({

Navigator.push任你推

})

最新更新