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

Flutter does not accept Color const

i created a file with the colors that i want to use in my project, but when i try to used, flutter does not acept the variables as a correct color.

This is the colors file:

import 'package:flutter/material.dart';

class ColorSkh {
     static Color innovation = const Color.fromARGB(255, 59, 18, 45);
     static Color fresh = const Color.fromARGB(255, 172, 155, 163);
     static Color hightech = const Color.fromARGB(255, 0, 128, 157);
     static Color sophisticated = const Color.fromARGB(255, 230, 231, 232);
     static Color sk = const Color.fromARGB(255, 191, 205, 217);
     static Color white = const Color.fromARGB(255, 255, 255, 255);
}

And this is how i am using it

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:analytic_skh/ui/color_skh.dart';
.
.
.


SizedBox(
                *height: height * 0.10,
                child: Align(
                    alignment: Alignment.centerLeft,
                    child: ElevatedButton.icon(
                      onPressed: onPressed,
                      icon: const Icon(Icons.settings),
                      label: const Text('Settings',
                          style:
                              TextStyle(backgroundColor: ColorSkh.innovation)),
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.white,
                      ),
                    )),
              )*




but i get the error that this is a invalid constant

>Solution :

Change your static colors to the const like below.

class ColorSkh {
  static const Color innovation = Color.fromARGB(255, 59, 18, 45);
  static const Color fresh = Color.fromARGB(255, 172, 155, 163);
  static const Color hightech = Color.fromARGB(255, 0, 128, 157);
  static const Color sophisticated = Color.fromARGB(255, 230, 231, 232);
  static const Color sk = Color.fromARGB(255, 191, 205, 217);
  static const Color white = Color.fromARGB(255, 255, 255, 255);
}
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