How to give background color to a RadioListTile using a RaisedButton?

1,778

Will wrapping the RadioListTile with Container and giving the color to Container solve your problem ?

enter image description here

Share:
1,778
Author by

momiavive

Updated on December 06, 2022

Comments

  • momiavive 19 minutes

    I have been trying to give background color to a RadioListTile by clicking the RaisedButton and create a function to assign that color to the RadioListTile that contains a certain value, for example value: 2. I'm using StatefulWidget.
    The code:

    int _radioValue = 0;
    int _answer = 2;
    void _handleRadioValueChange(int value) {
      setState(() {
        _radioValue = value;
      });
    }
    Scaffold(
      appBar: AppBar(
        title: Text('Question #1'),
        backgroundColor: Colors.teal,
      ),
      body: ListTileTheme(
        child: ListView(
          children: <Widget>[
            Container(
              padding: EdgeInsets.all(20.0),
              margin: EdgeInsets.all(10.0),
              color: Colors.tealAccent,
              child: Text('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec porttitor laoreet volutpat. Suspendisse malesuada ante. ',
                textAlign: TextAlign.center,
              ),
            ),
            RadioListTile(
              title: Text('Option #1'),
              value: 0,
              groupValue: _radioValue,
              onChanged: _handleRadioValueChange,
            ),
            RadioListTile(
              title: Text('Option #2'),
              value: 1,
              groupValue: _radioValue,
              onChanged: _handleRadioValueChange,
            ),
            RadioListTile(
              title: Text('Option #3'),
              value: 2,
              groupValue: _radioValue,
              onChanged: _handleRadioValueChange,
            ),
            RadioListTile(
              title: Text('Option #4'),
              value: 3,
              groupValue: _radioValue,
              onChanged: _handleRadioValueChange,
            ),
            RadioListTile(
              title: Text('Option #5'),
              value: 4,
              groupValue: _radioValue,
              onChanged: _handleRadioValueChange,
            ),
            RaisedButton(
              child: Text('Show Answer'),
              onPressed: (){},
              color: Colors.tealAccent,
              splashColor: Colors.teal,
            ),
          ],
        ),
      ),
    );
    
    • Dinesh Balasubramanian
      Dinesh Balasubramanian about 4 years
      On click of RaisedButton, you want to change the color of one radioTile. Is that right?
    • momiavive about 4 years
      @DineshBalasubramanian the background color dude.
  • momiavive about 4 years
    Yes, in part. Just missing the function to do what I described initially. Thanks dude.