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

Request: Change color from external widget #6

Closed
S-Man42 opened this issue Apr 9, 2020 · 10 comments
Closed

Request: Change color from external widget #6

S-Man42 opened this issue Apr 9, 2020 · 10 comments

Comments

@S-Man42
Copy link

S-Man42 commented Apr 9, 2020

Use Case: User wants to see how a certain color code looks like. So he enters, e.g., a hex code and the color picker should show this color.

Is it possible to inject a Color value to the picker?

@itome
Copy link
Owner

itome commented Apr 9, 2020

You can change the color by changing initial color.

class SomeViewState extends State<SomeView> {
  Color selectedColor = Colors.red;

  Widget build(BuildContext context) {
    return Column(
      children: [
        CircleColorPicker(
          initialColor: selectedColor,
          onChanged: (color) => this.setState({ selectedColor: color }),
          size: const Size(240, 240),
          strokeWidth: 4,
          thumbSize: 36,
        ),
        TextField(
          onChanged: (text) => this.setState({selectedColor: Color(text)})
        ),
      ]
    );
  }
}

@S-Man42
Copy link
Author

S-Man42 commented Apr 9, 2020

Your code gives the error "error: The argument type 'Map<Color, Color>' can't be assigned to the parameter type 'void Function()'. (argument_type_not_assignable at ...)" for the setState() lines.

I tried this:

class ColorPickerState extends State<ColorPicker> {
  Color _currentColor = Colors.red;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        CircleColorPicker(
          initialColor: _currentColor,
          strokeWidth: 6,
          onChanged: (Color color) {
            setState(() {
              _currentColor = color;
            });
          },
        ),
       TextField(
          onChanged: (text) {
            setState(() {
              _currentColor = Colors.yellow; // the red value should turn into yellow when entering something into the TextField
            });
          },
        )
      ],
    );
  }
}

But it does nothing. When I have a look into your code, the controller values are only set in initState(), am I right? In that case, after creating the widget, the controller never changes its value.

@S-Man42
Copy link
Author

S-Man42 commented Apr 11, 2020

Hi,

do have a solution for this? I tried do change your code by myself but I believe, things got even worse with my approach :D

I really would appreciate a solution here, as well. Because without it, I couldn't use your very nice component anyway. I do need to be able to set values from external widgets (so the component becomes both: A color picker and a color viewer :D)

@itome
Copy link
Owner

itome commented Apr 13, 2020

Currently approach above doesn't work because of a bug in library. I'm working on this issue.

@S-Man42
Copy link
Author

S-Man42 commented Apr 19, 2020

Hi :)

Do you have any news here? It would be awesome to get this feature. Currently my feature branch is waiting for this, because I'd love to integrate you widget. Do you have any idea if or when you get it fixed? (for planning purposes ;))

@itome
Copy link
Owner

itome commented May 18, 2020

Sorry, I was busy last month. I'll fix this until the end of May.

@jdeltoft
Copy link

+1 on this. I love your work! I'm using it with Hubitat to play with a neopixel. I wanted to pull the current color from the LED on start up/resume of flutter, but I don't see any way to set the color wheel to a value.

@CripyIce
Copy link

Great library and looking forward for this new feature!
Will it be ready soon?

@AliRn76
Copy link

AliRn76 commented Oct 19, 2020

we need a controller for this widget, can we create one for this :\

@itome
Copy link
Owner

itome commented Apr 19, 2021

@S-Man42 Sorry for being very late!
I merged PR #21 which add controller parameter to control picker color from outside.
Thanks.

@itome itome closed this as completed Apr 19, 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

5 participants