Explain Navigator Widget and its push/pop functions in Flutter?
Explain Navigator Widget and its push/pop functions in Flutter?
The Navigator widget in Flutter is used for managing a stack of Route objects, where each Route represents a full-screen widget. It provides methods for pushing and popping routes to navigate between screens[4].
To navigate to a new route, use the Navigator.push()
method. This adds a new Route to the top of the Navigator's stack[4]:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
The MaterialPageRoute
is commonly used as it provides a platform-specific animation when transitioning to the new route[4].
To return to the previous route, use the Navigator.pop()
method. This removes the current Route from the Navigator's stack[4][5]:
Navigator.pop(context);
If you want to pass data back to the previous route when popping, you can provide a result argument to pop()
[5]:
Navigator.pop...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào