Home > database >  flutter change the color of utils const color , in the app screen using button
flutter change the color of utils const color , in the app screen using button

Time:09-05

I wrote a big software, I tried to use 2 main colors for the whole software. I want to change the overall color of the software by pressing a button. I need your help.

on the lib/utils: SO:they are not in the class,

const d = Color.fromARGB(255, 184, 233, 8);

const w = Color.fromARGB(255, 255, 255, 255);

on every page i made i used it like under code to change colors that i used:

color:d,

or

color:w,

now i made button and want to use it like:

AppBar(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.only(
                      bottomLeft: Radius.circular(25.0),
                      bottomRight: Radius.circular(25.0))),
              toolbarHeight: 40,
              backgroundColor: d,
              foregroundColor: w,
              bottomOpacity: 0.1,
              centerTitle: false,
              title: SvgPicture.asset(
                'assets/ic_instagram.svg',
                color: primaryColor,
                height: 25,
              ),
              actions: [
                IconButton(
                  icon: Icon(
                    Icons.mail,
                    color: Color.fromARGB(255, 255, 0, 191),
                  ),
                  onPressed: () {
                    setState(() {
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => colorset(),
                        ),
                      );
                    });
                  },
                ),
                IconButton(
                  icon: Icon(
                    Icons.mail,
                    color: Color.fromARGB(255, 1, 132, 255),
                  ),
                  onPressed: () {
                    setState(() {
                      d.update(d: Color.fromARGB(255, 1, 132, 255));
                    });
                  },
                ),
              ],
            ),

how is it possible to change the color of const values in utils?

CodePudding user response:

If you want to change your color variables why don't you just remove the const?

Use const for variables that do not change anymore (e.g. PI)

Color w = Color.fromARGB(255, 184, 233, 8);
  • Related