show method

Future<void> show(
  1. BuildContext context, {
  2. required List<SpotlightTarget> targets,
  3. List<Rect>? extraHoles,
  4. List<Path>? extraHolePaths,
  5. SpotlightStyle style = const SpotlightStyle(),
})

Shows a spotlight overlay highlighting the given targets.

The context is used to insert the overlay. You can optionally provide extraHoles or extraHolePaths to create additional transparent areas, and customize the appearance with style.

If a spotlight is already showing, this method returns early without making changes.

Implementation

Future<void> show(
  BuildContext context, {
  required List<SpotlightTarget> targets,
  List<Rect>? extraHoles,
  List<Path>? extraHolePaths,
  SpotlightStyle style = const SpotlightStyle(),
}) async {
  if (_overlayEntry != null) {
    return;
  }
  if (targets.isEmpty) {
    return;
  }

  await _removeCurrentOverlay(animate: false);

  final overlayState = _findOverlayState(context);
  if (overlayState == null) {
    return;
  }

  _overlayKey = GlobalKey<SpotlightOverlayState>();
  _overlayEntry = OverlayEntry(
    builder: (_) => SpotlightOverlay(
      key: _overlayKey,
      targets: targets,
      extraHoles: extraHoles,
      extraHolePaths: extraHolePaths,
      style: style,
    ),
  );

  overlayState.insert(_overlayEntry!);
}