How to access the Widget from within its own callback onPressed in Dart

Posted by Jennifer | Updated on

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:


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.

Related Questions & Answers