Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate from one screen to another (start activity) and close current screen (finish) in 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.

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();

Thanks.

like image 394
Jayesh Avatar asked Jun 19 '18 12:06

Jayesh


People also ask

How do you go from one activity to another activity in Flutter?

To navigate from one screen to another, you must use the Navigator .

How do I close the current screen in Flutter?

Dart. SystemNavigator. pop(); We will use the Text Button at to call the Navigator pop method that will end the user screen.


1 Answers

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);
like image 143
Dhiraj Sharma Avatar answered Nov 15 '22 08:11

Dhiraj Sharma