flutter - 如何在 Flutter 中更改 Radio 小部件的边框颜色?
问题描述
我目前拥有的
我想要达到的目标
我现在拥有的代码
Radio(
value: 2,
groupValue: val,
onChanged: (value) {
setState(() {
val = value;
});
},
activeColor: secondaryColor,)
解决方案
无法自定义那么多单选按钮。按钮的唯一颜色参数是 fillColor。它将影响内圆和外圆。
如果您真的想要自定义外观,则需要构建自己的小部件。这是一个您可以自定义和改进的简单示例。您也可以尝试从 Flutter Radio 小部件的源代码开始。
class CustomRadio extends StatefulWidget {
final int value;
final int groupValue;
final void Function(int) onChanged;
const CustomRadio({Key? key, required this.value, required this.groupValue, required this.onChanged})
: super(key: key);
@override
_CustomRadioState createState() => _CustomRadioState();
}
class _CustomRadioState extends State<CustomRadio> {
@override
Widget build(BuildContext context) {
bool selected = (widget.value == widget.groupValue);
return InkWell(
onTap: () => widget.onChanged(widget.value),
child: Container(
margin: const EdgeInsets.all(4),
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(shape: BoxShape.circle, color: selected ? Colors.white : Colors.grey[200]),
child: Icon(
Icons.circle,
size: 30,
color: selected ? Colors.deepPurple : Colors.grey[200],
),
),
);
}
}
结果 :
推荐阅读
- python - 拟合曲线时的 TypeError
- sql - 在不引用对偶表的情况下,在 Oracle 中从无中选择?
- r - 需要找到一个模式并将其提取出来
- sql - SQL | 无论最后一个整数值如何,如何总是四舍五入,即使它可能是 0
- javascript - 方括号中的对象和某些键如何工作?
- html - Python3 Django Webapp HTML 测试按钮打印调试数据
- postman - Postman 未授权 Slack App
- android - 如何在 react-native 中添加破折号或虚线边框?
- django - 基于 Celery 类的任务同步运行而不是异步运行
- c# - 尝试从 Opc 服务器获取历史数据时如何修复“BadServiceUnsupported”错误