'How to dynamically change the background color of an Appbar and a button with a button?

I would like to change the color of an AppBar, text, and button with a button and its onPressed function.

I would like the color to update when tapping/pressing the button.

The colors of AppBar, text, and button would be different for each one.



Solution 1:[1]

Create two variables to store the color value.

Color _appBarColor = Colors.blue , _textColor=Colors.white;

Change the value of the variables on button pressed

onTap:(){
_appBarColor = Colors.grey;
_textColor = Colors.white;
setState((){}); //-> To Change the state of the screen
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kashif Niaz