🚰 TapCanvas

Detect taps outside the currently defined widget and provide a callback when taps occur.

codecov

Example

Define the area within which you care about taps

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => MaterialApp(
    home: TapCanvas(
      child: MyHomeWidget(),
    ),
  );
}

Now your widgets can react when the user taps outside them

class TapOutsideAwareWidget extends StatelessWidget {
  const TapOutsideAwareWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => TapOutsideDetectorWidget(
    onTappedOutside: () {
      print('OUTSIDE TAPPED');
    },
    onTappedInside: () {
      print('INSIDE TAPPED');
    },
    child: MyWidgetThatCaresAboutTaps(),
  );
}

Libraries

tap_canvas