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

标签 flutter flutter-layout

我一直在尝试通过单击 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/

相关文章:

android - 如何通过 flutter 应用程序提供共享选项

flutter - 如何使Widget属性在flutter中成为可选

flutter - 如何将不同大小的文本对齐在一行中

flutter - 边框半径不适用于带有选项卡 View 小部件的容器小部件。我想要如图所示

android - Flutter:为 ButtonBar 中的两个按钮提供相等的宽度,并为长文本提供动态高度

flutter - 如何在 Flutter 中将系统剪贴板文本(复制、粘贴等)的语言更改为中文?

dart - 使 AppBar 透明并显示设置为全屏的背景图像

dart - 在 TextInputType 更改后 Controller 重置的 Flutter TextField

flutter - 断言失败 : line 5143 pos 16: 'child is! ParentDataElement<ParentData>' : is not true

flutter - 如何获取 BouncingScrollPhysics overscroll 值偏移量?