routerState function

RestorableCell<CellRouterState> routerState({
  1. required String restorationId,
  2. CellRouterState? initial,
})

Restorable route-state factory.

Creates a RestorableCell holding a CellRouterState, persisted through Flutter's restoration protocol (JSON codecs; the extra field is not restored — see CellRouterState). Pair with a CellRestorationScope for the route to survive process kill.

(A Cell.routerState extension spelling is not reachable from another package — Dart extension statics belong to the extension, not the extended type — so the factory ships as this top-level function.)

Implementation

RestorableCell<CellRouterState> routerState({
  required String restorationId,
  CellRouterState? initial,
}) {
  return restorableState<CellRouterState>(
    restorationId: restorationId,
    initial: initial ?? const CellRouterState(location: '/'),
    toPrimitives: (state) => state?.toJson(),
    fromPrimitives: (data) => CellRouterState.fromJson(
      data is Map<Object?, Object?> ? data : const {},
    ),
  );
}