Flutter错误:查找已停用小部件的祖先是不安全的

huangapple go评论77阅读模式
英文:

flutter error Looking up a deactivated widget's ancestor is unsafe

问题

我试图让启动屏幕只显示5秒钟,但我遇到了以下错误。flutter错误

我的Dart代码splashScreen代码

英文:

I am trying to make the splashscreen display for 5 seconds only but I have the following error.flutter error

my dart codesplashScreen code

答案1

得分: 0

将SplashScreen类转换为StatefulWidget。然后在initState()中,延迟4秒后进行导航。

@override
void initState() {
  Future.delayed(const Duration(seconds: 4)).then((value) {
    Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
      return const HomePage();
    }));
  });
  super.initState();
}
英文:

convert SplashScreen class into StateFulWidget.
then inside initState() navigate after 4 seconds.

 @override
 void initState() {
  Future.delayed(const Duration(seconds: 4)).then((value) {
  Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
   return const HomePage();
  },));
});
super.initState();
}

huangapple
  • 本文由 发表于 2023年2月24日 15:00:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553453.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定