diff --git a/lib/src/widgets/color_button.dart b/lib/src/widgets/color_button.dart index 79f5999..b933a7b 100644 --- a/lib/src/widgets/color_button.dart +++ b/lib/src/widgets/color_button.dart @@ -175,7 +175,7 @@ class _ColorButtonState extends State with WidgetsBindingObserver { EyeDrop.of(context).capture(context, (value) { hidden = false; _onEyePick(value); - }); + }, null); } catch (err) { print('ERROR !!! _buildPickerOverlay $err'); } diff --git a/lib/src/widgets/eyedrop/eye_dropper_layer.dart b/lib/src/widgets/eyedrop/eye_dropper_layer.dart index 143b97f..dee12a2 100644 --- a/lib/src/widgets/eyedrop/eye_dropper_layer.dart +++ b/lib/src/widgets/eyedrop/eye_dropper_layer.dart @@ -28,6 +28,8 @@ class _EyeDropperModel { ValueChanged? onColorSelected; + ValueChanged? onColorChanged; + _EyeDropperModel(); } @@ -74,6 +76,7 @@ class EyeDrop extends InheritedWidget { data.eyeOverlayEntry!.remove(); data.eyeOverlayEntry = null; data.onColorSelected = null; + data.onColorChanged = null; } catch (err) { debugPrint('ERROR !!! _onPointerUp $err'); } @@ -91,16 +94,21 @@ class EyeDrop extends InheritedWidget { data.hoverColor = getPixelColor(data.snapshot!, offset); data.hoverColors = getPixelColors(data.snapshot!, offset); } + + if (data.onColorChanged != null) { + data.onColorChanged!(data.hoverColors.center); + } } - void capture( - BuildContext context, ValueChanged onColorSelected) async { + void capture(BuildContext context, ValueChanged onColorSelected, + ValueChanged? onColorChanged) async { final renderer = captureKey.currentContext?.findRenderObject() as RenderRepaintBoundary?; if (renderer == null) return; data.onColorSelected = onColorSelected; + data.onColorChanged = onColorChanged; data.snapshot = await repaintBoundaryToImage(renderer); diff --git a/lib/src/widgets/eyedrop/eyedropper_button.dart b/lib/src/widgets/eyedrop/eyedropper_button.dart index cf162ab..c6a1c5d 100644 --- a/lib/src/widgets/eyedrop/eyedropper_button.dart +++ b/lib/src/widgets/eyedrop/eyedropper_button.dart @@ -15,8 +15,12 @@ class EyedropperButton extends StatelessWidget { /// color selection callback final ValueChanged onColor; + /// hover, and the color changed callback + final ValueChanged? onColorChanged; + const EyedropperButton({ required this.onColor, + this.onColorChanged, this.icon = Icons.colorize, this.iconColor = Colors.black54, Key? key, @@ -40,7 +44,7 @@ class EyedropperButton extends StatelessWidget { void _onEyeDropperRequest(BuildContext context) { try { - EyeDrop.of(context).capture(context, onColor); + EyeDrop.of(context).capture(context, onColor, onColorChanged); } catch (err) { throw Exception('EyeDrop capture error : $err'); } diff --git a/lib/src/widgets/eyedrop/eyedropper_button_web.dart b/lib/src/widgets/eyedrop/eyedropper_button_web.dart index c05eacd..62766eb 100644 --- a/lib/src/widgets/eyedrop/eyedropper_button_web.dart +++ b/lib/src/widgets/eyedrop/eyedropper_button_web.dart @@ -16,11 +16,15 @@ class EyedropperButton extends StatelessWidget { /// color selection callback final ValueChanged onColor; + /// hover, and the color changed callback + final ValueChanged? onColorChanged; + /// verify if the button is in a CanvasKit context bool get eyedropEnabled => js.context['flutterCanvasKit'] != null; const EyedropperButton({ required this.onColor, + this.onColorChanged, this.icon = Icons.colorize, this.iconColor = Colors.blueGrey, Key? key, @@ -41,7 +45,7 @@ class EyedropperButton extends StatelessWidget { void _onEyeDropperRequest(BuildContext context) { try { - EyeDrop.of(context).capture(context, onColor); + EyeDrop.of(context).capture(context, onColor, onColorChanged); } catch (err) { throw Exception('EyeDrop capture error : $err'); }