rydmike / flex_color_picker

A highly customizable Flutter color picker.
BSD 3-Clause "New" or "Revised" License
197 stars 41 forks source link

Dialog with Future<Color?> return type #13

Closed aloisdeniel closed 3 years ago

aloisdeniel commented 3 years ago

Hi Mick!

Great work BTW!

I have a suggestion regarding the dialog picker.

I'm not fond of the way it is implemented and I would have preferred a "stateless" way of doing things without relying on the onColorChanged callback.

An API like this would feel more natural to me :

Future<Color?> showColorPickerDialog(
   BuildContext context,
   Color? selectedColor,
   /// Picker properties
   /// Same properties as ColorPicker widget
  );

This way I find it more natural to use from a button from example :

Button(
  onTap: () async {
     final newColor = await showColorPickerDialog(context, color, ...);
  }
)

What do you think?

Edit

I understand why you did that: this allows you to update the view behind the picker while shown to the user!

Maybe having the two alternatives would be the best then. :)

rydmike commented 3 years ago

Hi Aloïs, yes it was indeed done in current, admittedly a bit awkward way, exactly for that reason. It was the simplest way I got it to update colors and theme's in the background, while the picker is open and operated in a dialog.

I tried the above variant too, but could not do it that way. However, like you say nothing prevents me from adding the proposed way as an alternative. It's definitely more convenient if you don't need that capability.

It should also be possible to make your own custom dialog and just use the ColorPicker() in it and handle the dialog that way then too. That is of course a bit extra work to setup, so it would certainly be nice to have it out of the box too, I will probably squeeze it in together with next pre-release.

The next pre-release contains a bunch of cleanup, some minor tweaks, so this should fit well in there. I have on purpose not released the 2.0.0-pre null-safety version to stable yet, as I have also been adding a bunch of features and they are not yet properly documented, and it also still need need some fine tuning.

The copy-paste handling options, simple toolbar buttons, keyboard shortcuts CTRL-C/V (CMD-C/V on Mac), long press and/or right click context copy-paste menus, was pretty interesting to add. As was the opacity slider, impressive how customizable the slider can be, had to dig quite deep into it. As always all options are configurable and optional.

The docs will take some time before I'm done with them, I've started, but lets see when I get the done: https://github.com/rydmike/flex_color_picker/tree/2-0-0-stable-p1#enable-shades-selection

The bundled Web demo will also contain API tooltips for all the config options, well it already does, but this is still a rather raw version https://rydmike.com/flexcolorpicker/#/

Future version will add mote picker type and color formats. Also for desktop I would like an overlay that pops up next to where your color pick activation item/button is and that you can also move around dialog.

😃

image

aloisdeniel commented 3 years ago

Wow, that looks great!

Great work, it is a great package. 🤗

rydmike commented 3 years ago

FYI, I just released the last pre-release of 2.0.0-nullsafety.5, I'm just going to do some final documentation review and typo corrections before I release it as stable 2.0.0.

It now includes the above requested API as well, but as a Color, not a Color?. If the picker is dismissed it returns the color that it was created with (which is also none null and required), otherwise the selected Color is returned, so it always returns a none null Color.

Usage example added to the readme file and to the default example here: https://pub.dev/packages/flex_color_picker/versions/2.0.0-nullsafety.5#dialog-colorpicker-function

The readme now also contains a rather extensive API guide. https://pub.dev/packages/flex_color_picker/versions/2.0.0-nullsafety.5#flexcolorpicker-api-guide which still needs some tweaking, but pretty comprehensive now.

The Live Web version has been updated to use this this new package version, it can be played with here: https://rydmike.com/flexcolorpicker/ Also of course linked to from the readme.

rydmike commented 3 years ago

Closing this suggestion, because the 2.0.0 release includes the suggestion. Thanks again Aloïs for the suggestion and input! 😃