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
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
2
Answers
You need to remove the color from the
Text
widget since it ca be constant anymore because those color variables arestatic
and notfinal
, so try this:Change your static colors to the
const
like below.