Learn

Application-owned page design

Choose neutral, Material or Cupertino pages with complete application-owned factories and a 1.x migration checklist.

v2.4.1Intermediate

This guide describes the 2.0 API. Typed destinations, stack operations, Guard and Redirect retain their roles; page construction is now independent of a particular design system.

A neutral starting point

An empty NavigationPresentation() now creates an opaque, unanimated page with zero transition duration. A Session can render through WidgetsApp.router without Material or Cupertino. The navigation library imports neither design system and does not select one from the operating system.

To give ordinary pages a cross-fade, pass this as the Graph's defaultPresentation:

dart
const NavigationPresentation(
  transition: NavigationTransitionKind.fade,
  duration: Duration(milliseconds: 220),
  reverseDuration: Duration(milliseconds: 180),
)

Other neutral choices are slide, none and custom. The custom kind requires transitionsBuilder; other kinds reject that builder. Neutral transitions obey MediaQuery.disableAnimations. A custom builder receives the context, forward animation, secondary animation and original child. A builder changes the visual transition, not the Route's gesture or dismissal implementation.

Keep Material pages

Add material_ui to your application's dependencies and implement this class there. It does not become an Ark Navigation runtime dependency.

dart
import 'package:ark_navigation/ark_navigation.dart';
import 'package:material_ui/material_ui.dart';

final class AppPageFactory implements NavigationPageFactory {
  const AppPageFactory();

  @override
  Page<Object?> createPage(final NavigationPageConfiguration configuration) =>
      configuration.presentation.surface == NavigationSurface.modal
      ? NavigationPages.createDefault(configuration)
      : MaterialPage<Object?>(
          key: configuration.key,
          name: configuration.name,
          restorationId: configuration.restorationId,
          fullscreenDialog: configuration.presentation.surface ==
              NavigationSurface.fullscreenDialog,
          child: configuration.child,
        );
}

Configure the Graph once with defaultPresentation: const NavigationPresentation(pageFactory: AppPageFactory()). Continue to connect your MaterialApp.router to the Session's routerConfig. The returned Material page uses the application's theme; the navigation package does not recreate it.

The example deliberately leaves modals neutral. createDefault preserves the surface, child and barrier settings without calling the factory again. To use a design-specific modal, return your own Page<Object?> whose createRoute constructs that Route. Handle surface and dismissal explicitly rather than silently substituting an opaque page for a modal.

Cupertino and custom designs

The same interface can return CupertinoPage<Object?> from package:cupertino_ui/cupertino_ui.dart. Preserve key, name, restorationId, fullscreenDialog and child. The host app supplies the design's required theme and localizations. An adaptive factory can choose a design using the application's own platform policy; this is no longer a decision made by Ark Navigation.

The runnable example selects Material globally and Cupertino on one route. No new ArkTelos adapter package, generated router or global factory registration is needed.

Overrides are complete values

Presentation is selected in the existing order:

  1. Operation override on NavigationTarget.
  2. Route Definition.
  3. Mount.
  4. Module.
  5. Graph default.

The values are not merged field by field. A route with an explicit neutral fade replaces the Graph's factory for that route. Configure once at Graph level and override only where behavior differs.

A pageFactory cannot be combined with another transition kind: leave transition at none. The factory owns its Route and animation. Neutral duration fields do not automatically change a Material/Cupertino Route's duration; the application factory must implement any such customization deliberately.

Identity and lifecycle

Factories receive immutable NavigationPageConfiguration, not a Controller or private Navigator key. The returned Page must preserve its key, name and restorationId; Ark Navigation validates them. Render the supplied child or wrap it: it already includes the pop/lifecycle boundary. Do not replace it with a different body. Arbitrary application code cannot be proven to render a child, so that part is an explicit factory contract, not a runtime safety claim.

Flutter supplies the real Navigator context to the Page's createRoute. Use that point for context-dependent route construction instead of retaining a BuildContext inside a long-lived factory.

Back gestures are not an animation preset

Selecting CupertinoPage does not bypass asynchronous leave Guards. The 2.2 Native Back integration registers a live PopEntry permission with the actual Route. An unguarded eligible page can allow a gesture; guarded pages require ahead-of-time permission from every effective NavigationBackGuard. An ordinary asynchronous Guard keeps the native path blocked and remains available to explicit Back. See the Native Back guide for the complete editor flow, result handling and widget-versus-device test boundary.

Typed pop, system-back, Guard rejection, nested stacks and restoration must stay correct independently of design. A fade or slide is not an implementation of these contracts. Neutral routes do not supply design-specific gestures.

Migration from 1.x

  • Replace removed adaptive, material, and cupertino enum cases with an application page factory.
  • Install an explicit factory if you relied on the former adaptive default. An empty configuration now means neutral, unanimated navigation.
  • Keep fade, slide, none or custom where they express the intended behavior.
  • Give dismissible neutral modals a meaningful, nonblank barrierLabel.
  • Migrate the app's imports, theme and delegates together using Flutter's official guide.
  • Check the real app's back behavior, dialogs, nested stacks, restoration, reduced motion, light/dark themes and non-English localizations before release.

This is a major change because public enum members and defaults change. Compatibility was validated with Flutter 3.50.1 / Dart 3.14.0; each application must still verify its own UI and back-navigation policy before shipping.