Explain Navigator Widget and its push pop functions in Flutter?

Technology CommunityCategory: FlutterExplain Navigator Widget and its push pop functions in Flutter?
VietMX Staff asked 3 years ago

Navigator Widget is a simple widget that maintains a stack of Routes, or in simpler terms, a history of visited screens/pages.

When we navigate to another screen, we use the push methods and Navigator widget adds the new screen onto the top of the stack.

new RaisedButton(  
	onPressed:(){  
	**Navigator._of_(context).pushNamed('/screen2');**  
},  
	child: new Text("Push to Screen 2"),  
),

Now when we want to get rid of the last visited screen, we would need to pop Routes from the Navigator’s stack using the pop methods.

Navigator._of_(context).pop();