holdForSheet method

void holdForSheet(
  1. ModalRoute route,
  2. GlassBarSheetItem item,
  3. GlassMorphAnchor anchor
)

Keeps item's capsule hoisted through the sheet about to be presented out of anchor.

Called by the pinned host on the tap, before the item presents, so the hold is in place by the frame the sheet's route lands and the group is never unmounted from under the droplet. A tap that presents nothing, or presents without the morph, leaves the anchor unemptied; such a hold is dropped at the end of the following frame and the chrome hands back as for any other presentation. So is one whose presentation has gone.

Implementation

void holdForSheet(
  ModalRoute<dynamic> route,
  GlassBarSheetItem item,
  GlassMorphAnchor anchor,
) {
  _dropSheetHold();
  final hold = _SheetHold(route: route, item: item, anchor: anchor);
  _sheetHold = hold;
  anchor.presentationChanges.addListener(_onSheetPresentationChanged);
  // The presenter empties the trigger during the sheet route's first build,
  // which is the coming frame. Still full at the end of it means no morph
  // is coming out of this capsule.
  WidgetsBinding.instance.addPostFrameCallback((_) {
    if (!mounted || !identical(_sheetHold, hold) || anchor.isPresenting) {
      return;
    }
    _dropSheetHold();
    _scheduleNotify();
  });
}