简体   繁体   中英

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

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?

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 (eg PI)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM