diff --git a/lib/src/pie_menu.dart b/lib/src/pie_menu.dart index e9659e0..676336f 100644 --- a/lib/src/pie_menu.dart +++ b/lib/src/pie_menu.dart @@ -22,6 +22,7 @@ class PieMenu extends StatelessWidget { this.onToggle, this.onPressed, this.onPressedWithDevice, + this.onPressedWithPosition, this.controller, required this.child, }); @@ -41,6 +42,7 @@ class PieMenu extends StatelessWidget { /// Functional callback triggered on press. /// /// You can also use [onPressedWithDevice] if you need [PointerDeviceKind]. + /// You can also use [onPressedWithPosition] if you need [Offset]. final Function()? onPressed; /// Functional callback triggered on press. @@ -49,6 +51,12 @@ class PieMenu extends StatelessWidget { /// Can be useful to distinguish between mouse and touch events. final Function(PointerDeviceKind kind)? onPressedWithDevice; + /// Functional callback triggered on press. + /// Provides [Offset] as a parameter. + /// + /// Can be useful to get the position of the menu. + final Function(Offset position)? onPressedWithPosition; + /// Controller for programmatically emitting [PieMenu] events. final PieMenuController? controller; @@ -63,6 +71,7 @@ class PieMenu extends StatelessWidget { onToggle: onToggle, onPressed: onPressed, onPressedWithDevice: onPressedWithDevice, + onPressedWithPosition: onPressedWithPosition, controller: controller, child: child, ); diff --git a/lib/src/pie_menu_core.dart b/lib/src/pie_menu_core.dart index ed96f21..63ac6b9 100644 --- a/lib/src/pie_menu_core.dart +++ b/lib/src/pie_menu_core.dart @@ -21,6 +21,7 @@ class PieMenuCore extends StatefulWidget { required this.onToggle, required this.onPressed, required this.onPressedWithDevice, + required this.onPressedWithPosition, required this.controller, required this.child, }); @@ -40,6 +41,7 @@ class PieMenuCore extends StatefulWidget { /// Functional callback triggered on press. /// /// You can also use [onPressedWithDevice] if you need [PointerDeviceKind]. + /// You can also use [onPressedWithPosition] if you need [Offset]. final Function()? onPressed; /// Functional callback triggered on press. @@ -48,6 +50,12 @@ class PieMenuCore extends StatefulWidget { /// Can be useful to distinguish between mouse and touch events. final Function(PointerDeviceKind kind)? onPressedWithDevice; + /// Functional callback triggered on press. + /// Provides [Offset] as a parameter. + /// + /// Can be useful to get the position of the menu. + final Function(Offset position)? onPressedWithPosition; + /// Controller for programmatically emitting [PieMenu] events. final PieMenuController? controller; @@ -319,6 +327,8 @@ class _PieMenuCoreState extends State 'Offset or alignment must be provided.', ); + widget.onPressedWithPosition?.call(_pressedOffset); + _notifier.canvas.attachMenu( rightClicked: rightClicked, offset: offset,