Reputation: 1462
Here is what I am using for checkbox in flutter. But I can set only border color for unchecked state, not method found for fill color inside of the checkbox. Please help me with this.
Theme(
data: ThemeData(unselectedWidgetColor: Colors.white),
child: Checkbox(
checkColor: Colors.blue,
activeColor: Colors.white,
value: rememberMe,
onChanged: (value) {
setState(() {
rememberMe = value;
});
},
),
)
Upvotes: 5
Views: 6782
Reputation: 945
Checkboxes have a property called fillColor
From the documentation, here is how to use it
Checkbox(
value: true,
onChanged: (_){},
fillColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return Colors.orange.withOpacity(.32);
}
return Colors.orange;
})
)
Upvotes: 1
Reputation: 9625
That is more related to design itself. An empty checkbox should be exactly that, empty. If you give it a fill color, you are kind of defeating the design purpose.
Regardless, you could achieve this by putting it inside a Container
with a background color and the width and height to only fill the CheckBox
:
return Center(
child: Container(
alignment: Alignment.center,
width: 14,
height: 14,
color: Colors.blue,
child: Checkbox(
checkColor: Colors.blue,
activeColor: Colors.white,
value: rememberMe,
onChanged: (value) {
setState(() {
rememberMe = value;
});
},
),
),
);
Upvotes: 8