Câu hỏi phỏng vấn Flutter
Câu hỏi

Explain Navigator Widget and its push/pop functions in Flutter?

Câu trả lời

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].

Pushing a new route

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]:

dart Copy
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].

Popping a route

To return to the previous route, use the Navigator.pop() method. This removes the current Route from the Navigator's stack[4][5]:

dart Copy
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]:

dart Copy
Navigator.pop...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What are Streams in Flutter/Dart?

middle

Do you know what Ephemeral state means?

middle

What is the difference between Scaffold and Container in Flutter?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào