Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reuse custom color with custom name

Tags:

flutter

dart

In Android I could do this in my colors.xml:

<color name="my_custom_blue">#F7DC16</color>

In Flutter the only way to reuse colors is to define them in the Theme. However I want to define my custom colors with custom names so I can use it like this:

color: Colors.myCustomBlue

Anybody know how to achieve this?

like image 573
最白目 Avatar asked Jul 10 '18 08:07

最白目


1 Answers

I would suggest you create your own custom colors in another file:

class Colors {
  static const Color myCustomBlack = const Color(0x8A000000);
  static const Color white = const Color(0xFFFFFFFF);
}

but if you want to use them in your project, with CupertinoColors there is no conflict but with material Colors, you should either change the class name to something like MyColors which I think is better or you can hide the Colors class from the Material Library. if you want to use them just import the dart file and you are good to go.

like image 163
Raouf Rahiche Avatar answered Sep 28 '22 22:09

Raouf Rahiche