I'm trying to create a color class in Flutter, My main objective, is that I will be able to access the colors from this class anywhere and change them when I need.
I have attempted to create like this, but I can't seem to access the variables:
import 'package:flutter/material.dart';
class ColorSelect {
Color cbuttons = const Color(0xFF1520A6);
//there will be other colors here
}
This is how I tried to get the color:
child: Text(
userManager.isLoggedIn ? 'Sair' : 'Entre ou cadastre-se >',
style: TextStyle(
color: ColorSelect.cbuttons,
fontWeight: FontWeight.bold
),
),
but accessing the color class like this didn't work.
Extending the answer from the comments.
I think you're confused about the concept of classes in dart (or any OOP language for that matter).
To access a property of a class, you have to instantiate it.
color: ColorSelect().cbuttons,
or use static properties.
class ColorSelect {
static Color cbuttons = const Color(0xFF1520A6);
}
I'll encourage you to research this.