-2

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:

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;
MendelG
  • 14,885
  • 4
  • 25
  • 52
azeter09
  • 181
  • 2
  • 13
  • I’m voting to close this question because: It's opinion based. – MendelG Jul 05 '22 at 13:30
  • Duplicate of: https://stackoverflow.com/questions/54069239/whats-the-best-practice-to-keep-all-the-constants-in-flutter – MendelG Jul 05 '22 at 13:37

2 Answers2

1

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;
MendelG
  • 14,885
  • 4
  • 25
  • 52
1

You can have a class that includes all you custom colors or icons you use, so you just call them like "AppColors.red100" or " AppIcons.heart"

Kris
  • 3,091
  • 20
  • 28