title: How to change the text button color on press in flutter?
body: <p>I wanted to create a page in my app using the Flutter where people can select from the options that I created using text buttons. The current result of my code is given below in the image. But I want to make it like that - after selecting one text button the background color of the button and the text color will be changed to something else. And unless the Next button is not selected, it will remain colored in that way.
  Is this possible using flutter? If it is, can you please help me with how to do it?</p>
  <p><a href="https://i.stack.imgur.com/fSuLk.png" rel="nofollow noreferrer">Added Text buttons in Flutter-example</a></p>
  <p>My Code -</p>
  <pre class="lang-dart prettyprint-override"><code>    class property_selection extends StatefulWidget {
        const property_selection({Key? key}) : super(key: key);
      
        @override
        _property_selectionState createState() =&gt; _property_selectionState();
      }
      
      class _property_selectionState extends State&lt;property_selection&gt; {
        @override
        Widget build(BuildContext context) {
          return SafeArea(
            child: Scaffold(
              body: Center(
                child: ListView(
                  shrinkWrap: true,
                  children: &lt;Widget&gt;[
                    Container(
                      margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      child: Text(
                        'Select your class',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Colors.red,
                            fontWeight: FontWeight.w500,
                            fontSize: 30),
                      ),
                    ),
                    SizedBox(
                      height: 15.0,
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(75, 0, 75, 0),
                      padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      height: 60.0,
                      child: TextButton(
                        onPressed: () {},
                        child: SizedBox(
                          width: double.infinity,
                          child: Text(
                            'Class 01',
                            textAlign: TextAlign.left,
                          ),
                        ),
                        style: ButtonStyle(
                          side: MaterialStateProperty.all(
                            BorderSide(width: 2, color: Colors.grey),
                          ),
                          backgroundColor: MaterialStateProperty.all(Colors.white),
                          foregroundColor: MaterialStateProperty.all(Colors.black),
                          padding: MaterialStateProperty.all(
                              EdgeInsets.symmetric(vertical: 10, horizontal: 50)),
                          textStyle: MaterialStateProperty.all(
                            TextStyle(fontSize: 15),
                          ),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 10.0,
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(75, 0, 75, 0),
                      padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      height: 60.0,
                      child: TextButton(
                        onPressed: () {},
                        child: SizedBox(
                          width: double.infinity,
                          child: Text(
                            'Class 02',
                            textAlign: TextAlign.left,
                          ),
                        ),
                        style: ButtonStyle(
                          side: MaterialStateProperty.all(
                            BorderSide(width: 2, color: Colors.grey),
                          ),
                          foregroundColor: MaterialStateProperty.all(Colors.black),
                          padding: MaterialStateProperty.all(
                              EdgeInsets.symmetric(vertical: 10, horizontal: 50)),
                          textStyle: MaterialStateProperty.all(
                            TextStyle(fontSize: 15),
                          ),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 10.0,
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(75, 0, 75, 0),
                      padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      height: 60.0,
                      child: TextButton(
                        onPressed: () {},
                        child: SizedBox(
                          width: double.infinity,
                          child: Text(
                            'Clas 03',
                            textAlign: TextAlign.left,
                          ),
                        ),
                        style: ButtonStyle(
                          side: MaterialStateProperty.all(
                            BorderSide(width: 2, color: Colors.grey),
                          ),
                          foregroundColor: MaterialStateProperty.all(Colors.black),
                          padding: MaterialStateProperty.all(
                              EdgeInsets.symmetric(vertical: 10, horizontal: 50)),
                          textStyle: MaterialStateProperty.all(
                            TextStyle(fontSize: 15),
                          ),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 10.0,
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(75, 0, 75, 0),
                      height: 50,
                      padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      child: ElevatedButton(
                        child: Text('Next'),
                        onPressed: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context) =&gt; customer_name()),
                          );
                        },
                      ),
                    ),
                  ],
                ),
              ),
            ),
          );
        }
      }`
  
  </code></pre>