ensurePage method

PageHandle ensurePage(
  1. String name, {
  2. String? description,
  3. required String route,
  4. Map<String, DslType>? params,
  5. Map<String, DslType>? state,
  6. List<DslAction>? onLoad,
  7. required DslWidget body,
  8. bool isInitial = false,
})

Declares a page idempotently — no-ops if the page already exists in the target project.

This is identical to page except that compilation silently skips the page creation when a page with the same name already exists. Use this to make brownfield patches safe to re-run without manual cleanup.

app.ensurePage('CreateTripPage', route: '/create-trip', body: ...);

Implementation

PageHandle ensurePage(
  String name, {
  String? description,
  required String route,
  Map<String, DslType>? params,
  Map<String, DslType>? state,
  List<DslAction>? onLoad,
  required DslWidget body,
  bool isInitial = false,
}) {
  _ensureNotPendingRemoval(_pendingRemovals, name, 'page', 'removePage');
  _ensureUnique(_pageNames, name, 'page');
  _ensurePageNames.add(name);
  final declaration = PageDeclaration(
    name: name,
    description: description,
    route: route,
    params: params,
    state: state,
    onLoad: onLoad,
    body: body,
    isInitial: isInitial,
  );
  _pages.add(declaration);
  return PageHandle(declaration);
}