gpt4 book ai didi

flutter - 如何使用 RaisedButton 为 RadioListTile 提供背景颜色?

转载 作者:IT王子 更新时间:2023-10-29 07:06:10 27 4
gpt4 key购买 nike

我一直在尝试通过单击 RaisedButtonRadioListTile 提供背景颜色,并创建一个函数将该颜色分配给 RadioListTile包含特定的 value,例如 value: 2。我正在使用 StatefulWidget
代码:

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,
),
],
),
),
);

最佳答案

Container 包装 RadioListTile 并将颜色赋予 Container 是否可以解决您的问题?

enter image description here

关于flutter - 如何使用 RaisedButton 为 RadioListTile 提供背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52390623/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com