If you want to access the Widget from within its own callback onPressed in Dart/fluter. You could make some of the properties a variable. Then you can call setState() in your onPressed() to change the property variable.
This example shows how to change your text color of the button by using this method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Color textColor = Colors.white; @override Widget build(BuildContext context) { return new Container( height: 72.0, // in logical pixels padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0), decoration: new BoxDecoration(color: Colors.white), // Row is a horizontal, linear layout. child: new MaterialButton( child: new Text( _sprinkler.name, style: new TextStyle(color: textColor) ), splashColor: Colors.blueAccent, color: Colors.blue[800], onPressed: () { this.setState(() { textColor = Colors.red; }) }, ), ); } |
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.