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

Using ColorPicker without ColorButton #10

Closed
BoHellgren opened this issue Sep 29, 2021 · 1 comment
Closed

Using ColorPicker without ColorButton #10

BoHellgren opened this issue Sep 29, 2021 · 1 comment

Comments

@BoHellgren
Copy link

In my drawing app, the user can tap on a field to change its color. This invokes an AlertDialog:

showDialog(
        context: context,
        builder: (context) {
          return SingleChildScrollView(
            child: AlertDialog(
              title: const Text('Pick a color!'),
              content: ColorPicker(
                color: oldColor,
                onChanged: (value){
                  chosenColor = value;
                },
              actions: <Widget>[
                Row(
                  children: [
                    TextButton(
                      child: const Text('Cancel'),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    ),
                    TextButton(
                      child: const Text('Save'),
                      onPressed: () {
                        artFields[fieldNo].fieldColor = chosenColor;
                        setState(() {});
                        Navigator.of(context).pop();
                      },
                    ),
                  ],
                ),
              ],
            ),
          );
        });

I cannot use ColorButton for this. I tried to use your version of ColorPicker but the results are strange (e.g. only some sliders react to taps and the rectangle at the bottom does not change color). I suppose using your ColorPicker directly this way is not supported? Should I give up on cyclop?

@rxlabz
Copy link
Owner

rxlabz commented Oct 5, 2021

I've just pushed an update, you should now be able to use it like this, but you will not be able to use the EyeDropper.

ElevatedButton(
              child: const Text('Open ColorPicker'),
              onPressed: () {
                showDialog(
                  context: context,
                  builder: (context) {
                    return Dialog(
                      child: ColorPicker(
                        selectedColor: backgroundColor,
                        onColorSelected: (value) =>
                            setState(() => backgroundColor = value),
                        config: const ColorPickerConfig( enableLibrary: false, enableEyePicker: false),
                        onClose: Navigator.of(context).pop,
                        onEyeDropper: () {},
                        onKeyboard: () {},
                      ),
                    );
                  },
                );
              },
            ),
          )

@rxlabz rxlabz closed this as completed Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants