showBeacon static method

void showBeacon(
  1. BuildContext context, {
  2. required GlobalKey<State<StatefulWidget>> key,
  3. required String beaconPosition,
  4. required Color color,
  5. required DataModel data,
  6. required dynamic onBeaconClicked(),
})

Implementation

static void showBeacon(
  BuildContext context, {
  required GlobalKey key,
  required String beaconPosition,
  required Color color,
  required DataModel data,
  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,
            data: data,
          );
          onBeaconClicked();
        },
      ),
    ),
  );

  overlay.insert(entry);

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