本文介绍了如何在Flutter中从一个屏幕导航到另一个屏幕(开始活动)并关闭当前屏幕(完成)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Flutter的初学者.
I am beginner to Flutter.
我有启动屏幕,可以从启动屏幕导航到登录屏幕,但是我无法销毁启动屏幕.
I have splash screen and I can navigate from splash to login screen, but I can't destroy the splash screen.
我想导航到登录屏幕后完成启动屏幕,就像android中的以下操作一样,如何在Flutter中实现这一目标.
I want to finish the splash screen after I navigate to login screen just like below action in android, how can I achieve this in Flutter.
startActivity(new Intent(this, Login.class));
finish();
谢谢.
推荐答案
使用MaterialPageRoute创建到小部件的路由.然后将您的路线以及上下文放到Navigator.pushReplacement完成当前屏幕,而push在其上创建新的小部件.
Use MaterialPageRoute to create route to your widget. Then place your route along with context to Navigator.pushReplacement finishes current screen while push creates new widget over it.
Route route = MaterialPageRoute(builder: (context) => YourWidget());
Navigator.pushReplacement(context, route);
这篇关于如何在Flutter中从一个屏幕导航到另一个屏幕(开始活动)并关闭当前屏幕(完成)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!