Pages as Data, UI via Resolver

Store only metadata in PageEntry. Choose buildPage to map each page key to an actual widget. The workflow remains easy to review.

Serializable state

PageEntry is plain data, so navigation state can be logged, diffed, and replayed. It can be inspected without constructing widgets. This also keeps team handoffs clear.

Simple resolver

A switch on page.key keeps routing explicit and reviewable. Each supported key visibly maps to one widget branch.

One source of truth

Push and pop are list operations on _pages, not side effects. The updated list becomes the single navigation state passed to the navigator.

Resolver Pattern

Build by page key and mutate the page list declaratively.

Page State Rule

Resolver Example

Widget _buildPage(BuildContext context, PageEntry page) {
  switch (page.key) {
    case 'home':
      return HomePage(onGoDetail: _goDetail);
    case 'detail':
      return const DetailPage();
    default:
      return const SizedBox.shrink();
  }
}

void _goDetail() {
  setState(() => _pages = [..._pages, const PageEntry(key: 'detail', name: '/detail')]);
}
Maintain Metadata Lean

Avoid placing. Widget instances into navigation state. and keep PageEntry as pure metadata for maintainability.