![](/img/trans.png)
[英]How to make Checkbox shape rounded in CheckboxListTile in Flutter?
[英]How to make checkbox ListTile with rounded box using Getx in Flutter
您可以使用shape字段和CircleBorder class 或RoundedRectangleBorder来制作一个 CheckBox 圆形(如果您希望它们具有圆角):
Checkbox(
checkColor: Colors.white,
value: isChecked,
shape: CircleBorder(),
onChanged: (bool? value) {
setState(() {
isChecked = value!;
});
},
);
或者:
Checkbox(
checkColor: Colors.white,
value: isChecked,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0))),
onChanged: (bool? value) {
setState(() {
isChecked = value!;
});
},
);
要使用 GetX,我认为您应该提供一些代码或示例来解释您的意思以及您想要准确实现的目标,否则最好的建议可能是阅读文档并检查一些示例。
正如您在屏幕截图中提到的那样。 您可以使用 GetX 实现它,如下所示:
创建一个变量以跟踪检查的值
final Rxn<int> selected = Rxn<int>();
现在您必须使用Obx小部件实现 UI 以侦听观察变量 ' selected ' 的变化
Obx( () => Column( children: [ CheckboxListTile( title: const Text('This is the title 1'), subtitle: const Text('This is the subtitle with ID 1'), checkColor: Colors.white, activeColor: Colors.blueGrey, controlAffinity: ListTileControlAffinity.leading, checkboxShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), value: selected.value == 1, onChanged: (val) { val?? true? selected.value = 1: selected.value = null; }, ), CheckboxListTile( title: const Text('This is the title 2'), subtitle: const Text('This is the subtitle with ID 2'), checkColor: Colors.white, activeColor: Colors.blueGrey, controlAffinity: ListTileControlAffinity.leading, checkboxShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), value: selected.value == 2, onChanged: (val) { val?? true? selected.value = 2: selected.value = null; }, ), ], ), ))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.