Want to toggle the color of a RaisedButton upon click in Flutter? This button will need to be created in the build of a State of a StatefulWidget, and the State must have a member variable bool pressAttention = false;. As Edman suggests, you need to make state changes in a setState callback for the Widget to redraw.
1 2 3 4 5 6 7 8 9 | new RaisedButton( child: new Text('Attention'), textColor: Colors.white, shape: new RoundedRectangleBorder( borderRadius: new BorderRadius.circular(30.0), ), color: pressAttention ? Colors.grey : Colors.blue, onPressed: () => setState(() => pressAttention = !pressAttention), ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.