tezvyn:

Explain the core responsibilities of RouterDelegate, RouteInformationParser, and Router in Flutter

AI-drafted, machine-checkedSource: api.flutter.devintermediate

Tests Navigator 2.0 architecture split. RouteInformationParser converts URLs to typed config; RouterDelegate owns state and builds the Navigator; Router wires them together and handles engine intents. Red flag: conflating parsing and state or omitting Router.

WHAT THIS TESTS: This question evaluates whether you understand the architectural separation of concerns in Flutter's Navigator 2.0 declarative routing API. It specifically probes if you know how data flows from the platform into the widget tree and which class owns state, parsing, and coordination.

A GOOD ANSWER COVERS: A good answer hits three responsibilities in order. First, RouteInformationParser converts raw route information strings from the platform into a strongly typed configuration object of type T. Second, RouterDelegate receives that configuration through setNewRoutePath or setInitialRoutePath, updates the app state accordingly, and builds the navigating widget tree typically a Navigator when the Router calls build. Third, Router is the widget that wires both delegates together, listens to route information providers and back button dispatchers from the engine, and triggers rebuilds. A strong candidate also notes that RouterDelegate must implement setNewRoutePath, popRoute, and build, and that it should notify listeners when state changes so Router can rebuild.

COMMON WRONG ANSWERS: A common wrong answer is saying RouterDelegate parses URLs or that RouteInformationParser builds widgets. Another red flag is omitting Router entirely and describing only a two-piece system. Some candidates also miss that RouterDelegate handles popRoute for system back button requests or confuse imperative push and pop with the declarative setNewRoutePath flow.

LIKELY FOLLOW-UPS: An interviewer might ask how deep linking works in this system, how state restoration uses currentConfiguration and setRestoredRoutePath, or how you would synchronize a bottom navigation bar with RouterDelegate. They may also ask why you would choose Navigator 2.0 over imperative navigation or how to handle unknown routes in RouteInformationParser.

ONE CONCRETE EXAMPLE: Imagine a book app where the URL is books/123. RouteInformationParser parses that string into a BookRouteConfig with id 123. RouterDelegate receives that config in setNewRoutePath, updates a selectedBookId in a listenable app state, and notifies listeners. The build method then returns a Navigator with two pages a BookListPage and a BookDetailPage for id 123. Router detects the engine intent, passes the parsed config to the delegate, and rebuilds the widget tree.

Read the original → api.flutter.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.