I have a checkbox added to my UI in Flutter app, I can see checkbox color or active color property but can't find any option to change border color of checkbox , which is usually black.
Whats the provision or tweak to change the border color ?
I have a checkbox added to my UI in Flutter app, I can see checkbox color or active color property but can't find any option to change border color of checkbox , which is usually black.
Whats the provision or tweak to change the border color ?
Checkbox(value: false, tristate: false, onChanged: () {});
↓
Theme(
data: ThemeData(unselectedWidgetColor: Colors.red),
child: Checkbox(value: false, tristate: false, onChanged: (bool value) {}));
No onChanged, then the border will be grey(disabled).
You can do it by using side
property...
side: BorderSide(color: Color(0xff585858)),
is case you wanna define app-wide theme for your checkboxes you can do this:
MaterialApp(
...
theme:ThemeData(
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateColor.resolveWith(
(states) {
if (states.contains(MaterialState.selected)) {
return Colors.purple // the color when checkbox is selected;
}
return Colors.white //the color when checkbox is unselected;
},
),
),
),
)
it is a good practice to define app-wide theme for your app to avoid code duplication and ensure consistency it also provides better maintenance. enjoy coding:)
Here is how you can change the color of text box outline
Checkbox(value: isChecked, onChanged: (val){
if(val != null) {
isChecked = val;
setState(() {
});
}
},checkColor: theme.primaryColor,
activeColor: theme.whiteColor,
hoverColor: theme.whiteColor,
side: BorderSide(
color: whiteColor, //your desire colour here
width: 1.5,
),
),
You can do this:
Container(
decoration: const BoxDecoration(
border: Border(
top: BorderSide(width: 3.0, color: Colors.red),
left: BorderSide(width: 3.0, color: Colors.red),
right: BorderSide(width: 3.0, color: Colors.red),
bottom: BorderSide(width: 3.0, color: Colors.red),
),
),
child: Checkbox(value: false, onChanged: null),
width: 20,
height: 20),
The BoxDecoration
class contains border
property that will let you customize the border sides and then you can add a Checkbox
and match the width and height of the container to the checkbox
Transform.scale( //For Increasing or decreasing Sizes
scale: 1.3,
child: Theme( // For Color Change,
data: ThemeData(unselectedWidgetColor: AppColors.checkBoxBorderColor),
child: Checkbox(
value: true,
shape: RoundedRectangleBorder( // Making around shape
borderRadius: BorderRadius.circular(2)),
onChanged: (isCheck) {},
activeColor: AppColors.checkBoxActiveColor,
),
),
),