route
declarative_nav

Declarative navigation and overlays for Flutter.

Drive Navigator 2.0 pages and screen-local overlays without Navigator.push/pop or showDialog.

layers

Pages Are Data

PageEntry stores metadata only. UI is created by your resolver.

slideshow

Screen-local Overlays

Dialogs and bottom sheets are scoped per screen without global state.

sync

State-agnostic

Use setState, Riverpod, Bloc, or Provider. No dependency required.

First Steps

Install declarative_nav and render pages using a resolver callback.

Installation

flutter pub add declarative_nav

Usage Guide

app_root.dart
class AppRoot extends StatefulWidget {
  const AppRoot({super.key});

  @override
  State<AppRoot> createState() => _AppRootState();
}

class _AppRootState extends State<AppRoot> {
  OverlayRequest? _overlay;
  late List<PageEntry> _pages;

  @override
  void initState() {
    super.initState();
    _pages = const [PageEntry(key: 'home', name: '/home')];
  }

  Widget buildPage(BuildContext context, PageEntry page) {
    return HomePage(onOpenDialog: _openDialog);
  }

  @override
  Widget build(BuildContext context) {
    return DeclarativePagesNavigator(
      pages: _pages,
      buildPage: buildPage,
      onPopTop: _popTop,
      canPopTop: () => _overlay == null,
    );
  }
}
info
Important Note

This package avoids Navigator.push/pop and showDialog calls. Drive navigation and overlays from state instead.

(c) 2024 declarative_nav Maintainers. Built for the Flutter community.