showBeacon static method

void showBeacon(
  1. BuildContext context, {
  2. required String shape,
  3. required GlobalKey<State<StatefulWidget>> key,
  4. required String beaconPosition,
  5. String? title,
  6. required String body,
  7. required Color color,
  8. required dynamic onBeaconClicked(),
})

Implementation

static void showBeacon(
  BuildContext context, {
  required String shape,
  required GlobalKey key,
  required String beaconPosition,
  String? title,
  required String body,
  required Color color,
  required Function() onBeaconClicked,
}) {
  // Get the render box for the target widget
  final RenderBox renderBox =
      key.currentContext!.findRenderObject() as RenderBox;
  final size = renderBox.size;
  final position = renderBox.localToGlobal(Offset.zero);

  Offset beaconOffset =
      calculateBeaconPosition(beaconPosition, position, size);
  // Use an OverlayEntry to display the pulse animation
  final overlay = Overlay.of(context);
  OverlayEntry? entry;
  entry = OverlayEntry(
    builder: (context) => Positioned(
      top: beaconOffset.dy, // Calculated top position
      left: beaconOffset.dx, // Calculated left position
      child: GestureDetector(
        child: PulseAnimation(
          color: color,
        ),
        onTap: () {
          entry!.remove();
          showTooltip(
            context,
            key: key,
            shape: shape,
            title: title,
            body: body,
          );
          onBeaconClicked();
        },
      ),
    ),
  );

  overlay.insert(entry);

  // Remove the overlay after a delay
  // Future.delayed(Duration(seconds: 3), () {
  //   entry.remove();
  // });
}