英文:
How to change the thickness of flutter checkbox
问题
After searching, I found a way to change the colors of the checkbox, but I did not find a way to change the thickness.
Is there any way other than using custom checkbox?
checkboxTheme: CheckboxThemeData(
checkColor: MaterialStateProperty.all(kWhiteColor),
fillColor: MaterialStateColor.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return kPrimaryColor; // the color when checkbox is selected;
}
return Colors.grey
.withOpacity(0.4); //the color when checkbox is unselected;
}),
Thanks.
英文:
After searching, I found a way to change the colors of the checkbox, but I did not find a way to change the thickness
Is there any way other than using custom checkbox
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
checkboxTheme: CheckboxThemeData(
checkColor: MaterialStateProperty.all(kWhiteColor),
fillColor: MaterialStateColor.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return kPrimaryColor; // the color when checkbox is selected;
}
return Colors.grey
.withOpacity(0.4); //the color when checkbox is unselected;
}),
<!-- end snippet -->
thanks
答案1
得分: 0
在Flutter中,CheckBox小部件带有一个名为side的属性。使用side属性,可以轻松更改复选框的样式、颜色、宽度等。
代码段示例:
Checkbox(
side: MaterialStateBorderSide.resolveWith(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const BorderSide(width: 3, color: Colors.red);
}
return const BorderSide(width: 2, color: Colors.green);
},
),
value: checkBoxValue,
onChanged: (bool? updatedValue) {
setState(() {
checkBoxValue = updatedValue!;
});
}
)
英文:
In flutter, the checkBox widget comes with a property named side .
Using the side property, one can easily change the check box's style, color, width, etc.
Code snippet example:
Checkbox(
side: MaterialStateBorderSide.resolveWith(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const BorderSide(width: 3, color: Colors.red);
}
return const BorderSide(width: 2, color: Colors.green);
},
),
value: checkBoxValue,
onChanged: (bool? updatedValue) {
setState(() {
checkBoxValue = updatedValue!;
});
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论