2

Is it possible to convert value of Material Color to Hex Code in flutter, I have been trying for a while now but i just cant work around it. any help would be appreciated.

3 Answers 3

3

There is a utils package that contains a ColorUtils class that can convert hex to int and int to hex. That can be used to create the Flutter colors or a HEX value from the Flutter color.

Github: https://github.com/Ephenodrom/Dart-Basic-Utils

PuDev: https://pub.dev/packages/basic_utils

Install :

basic_utils: ^2.0.0

Example :

Color color = Color(ColorUtils.hexToInt("#FFFFFF"));
String hex = ColorUtils.intToHex(color.value);
Sign up to request clarification or add additional context in comments.

1 Comment

You shouldn't use a package for functionality that exists in Dart by itself.
2

Take the integer representation and convert it into a hexadecimal string:

String hexCode = '#${color.value.toRadixString(16).padLeft(8, '0')}';

Comments

0
const Color colorPrimary = const Color(0xFF32ad79);
int hexCode = colorPrimary.value 

Comments

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.