close method

Future<void> close(
  1. BuildContext context
)

Collapses or closes the active detail view, checking onWillCollapse if provided.

Implementation

Future<void> close(BuildContext context) async {
  if (onWillCollapse != null) {
    final allowed = await onWillCollapse!(controller.value.activeKey);
    if (!allowed) return;
  }

  if (!context.mounted) return;

  // Mutating the controller synchronously notifies the table, which runs
  // _syncDetailFlow and already pops the active dialog/page/sideOverlay
  // route itself. Popping again here would race that pop (it can land on
  // the wrong route once the first pop already advances the Navigator),
  // so this is the only place the overlay gets dismissed.
  if (controller.value.isCreatingItem) {
    controller.cancelCreateItem();
  } else if (controller.value.isEditingItem) {
    controller.cancelEditItem();
  } else {
    controller.collapseDetail();
  }
}