Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onColorChanged callback #11

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/widgets/color_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class _ColorButtonState extends State<ColorButton> with WidgetsBindingObserver {
EyeDrop.of(context).capture(context, (value) {
hidden = false;
_onEyePick(value);
});
}, null);
} catch (err) {
print('ERROR !!! _buildPickerOverlay $err');
}
Expand Down
12 changes: 10 additions & 2 deletions lib/src/widgets/eyedrop/eye_dropper_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class _EyeDropperModel {

ValueChanged<Color>? onColorSelected;

ValueChanged<Color>? onColorChanged;

_EyeDropperModel();
}

Expand Down Expand Up @@ -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');
}
Expand All @@ -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<Color> onColorSelected) async {
void capture(BuildContext context, ValueChanged<Color> onColorSelected,
ValueChanged<Color>? onColorChanged) async {
final renderer =
captureKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;

if (renderer == null) return;

data.onColorSelected = onColorSelected;
data.onColorChanged = onColorChanged;

data.snapshot = await repaintBoundaryToImage(renderer);

Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/eyedrop/eyedropper_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ class EyedropperButton extends StatelessWidget {
/// color selection callback
final ValueChanged<Color> onColor;

/// hover, and the color changed callback
final ValueChanged<Color>? onColorChanged;

const EyedropperButton({
required this.onColor,
this.onColorChanged,
this.icon = Icons.colorize,
this.iconColor = Colors.black54,
Key? key,
Expand All @@ -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');
}
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/eyedrop/eyedropper_button_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ class EyedropperButton extends StatelessWidget {
/// color selection callback
final ValueChanged<Color> onColor;

/// hover, and the color changed callback
final ValueChanged<Color>? 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,
Expand All @@ -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');
}
Expand Down