1
Color pickerColor = new Color(0xff38ada9);
String colorString = pickerColor.toString();
Color newColor = Color(pickerColor.value);

But I got this error

Only static members can be accessed in initializers.

String colorString = this.pickerColor.toString();
Color newColor = Color(this.pickerColor.value);

I tried this and I got this error

Invalid reference to 'this' expression

Any suggestions ?

1

2 Answers 2

1

Replace

Color pickerColor = new Color(0xff38ada9);

with

static Color pickerColor = new Color(0xff38ada9);

And you won't have any error in

String colorString = pickerColor.toString();
Color newColor = Color(pickerColor.value);
Sign up to request clarification or add additional context in comments.

Comments

0

Only static members can be accessed in initializers.

Never initialize a class variable during it's declaration unless it is static. But making the variable static will create a common copy for all the objects/Widgets you create with it. Also, it will be easily accessible outside the class.

Note : This error has no relation with your question.

In order to convert Color to String you'll just need to use toString() getter function on the color in which you want to convert to String.

Sample Code:

Color(0xffffffff).toString() // This is what you were looking for.

2 Comments

Nothing leave it
You can delete your comments if you wish to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.