Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the best convention to store colors and icons in my Flutter app?

What is the best way to store colors in the flutter application?
currently, it looks like this: (is that a good way?)

I would like to know the best way

Example of colors:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import 'package:flutter/material.dart';

const Color orange = Color(0xFFFF6C00);

const Color purple1 = Color(0xFF7B1FA2);

Example of icons:

import 'package:flutter/material.dart';

const IconData checkIcon = Icons.check;

const IconData maleIcon = Icons.male;

const IconData femaleIcon = Icons.female;

>Solution :

You can have a separate file named constants.dart to store all your constants.
You should also name each constant with a preface with the letter K, so it’s easier to find when using your IDE’s auto-suggestions – you just need to type in the letter K.

for example, in your constants.dart file:

import 'package:flutter/material.dart';

const IconData KcheckIcon = Icons.check;

const IconData KmaleIcon = Icons.male;

const IconData KfemaleIcon = Icons.female;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading