showOverlay function

OverlaySupportEntry showOverlay (
  1. AnimatedOverlayWidgetBuilder builder,
  2. {Curve curve,
  3. Duration duration,
  4. Key key}
)

basic api to show overlay widget

duration the overlay display duration , overlay will auto dismiss after duration if null , will be set to kNotificationDuration if zero , will not auto dismiss in the future

builder, see AnimatedOverlayWidgetBuilder

curve, adjust the rate of change of an animation

key to identify a OverlayEntry.

for example:

final key = ValueKey('my overlay');

//step 1: popup a overlay
showOverlay(builder, key: key);

//step 2: popup a overlay use the same key
showOverlay(builder2, key: key);

if the notification1 of step1 is showing, the step2 will dismiss previous notification1.

if you want notification1' exist to prevent step2, please see ModalKey

Implementation

OverlaySupportEntry showOverlay(
  AnimatedOverlayWidgetBuilder builder, {
  Curve curve,
  Duration duration,
  Key key,
}) {
  assert(key is! GlobalKey);
  assert(_debugInitialized, 'OverlaySupport Not Initialized ! \nensure your app wrapped widget OverlaySupport');

  duration ??= kNotificationDuration;

  final OverlayState overlay = _overlayState;
  if (overlay == null) {
    assert(() {
      debugPrint('overlay not avaliable, dispose this call : $key');
      return true;
    }());
    return OverlaySupportEntry.empty();
  }

  final overlayKey = _OverlayKey(key);

  final supportEntry = OverlaySupportEntry._entries[overlayKey];
  if (supportEntry != null && key is ModalKey) {
    // Do nothing for modal key if there be a OverlayEntry hold the same model key
    // and it is showing.
    return supportEntry;
  }

  final dismissImmediately = key is TransientKey;
  // If we got a showing overlay with [key], we should dismiss it before showing a new.
  supportEntry?.dismiss(animate: !dismissImmediately);

  final stateKey = GlobalKey<_AnimatedOverlayState>();
  OverlaySupportEntry entry = OverlaySupportEntry(OverlayEntry(builder: (context) {
    return _KeyedOverlay(
      key: overlayKey,
      child: _AnimatedOverlay(
        key: stateKey,
        builder: builder,
        curve: curve,
        animationDuration: kNotificationSlideDuration,
        duration: duration,
      ),
    );
  }), overlayKey, stateKey);

  overlay.insert(entry._entry);

  return entry;
}