问题
How to change checkbox border-color in flutter? By default, it is showing black but I want it in grey.
回答1:
CheckBox's border color comes from unselectedWidgetColor of your ThemeData.
Add following ThemeData to your MaterialApp
MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
unselectedWidgetColor: Colors.red, // <-- your color
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
If you don't want to add color to the MaterialApp's ThemeData then you can wrap your CheckBox widget with Theme widget, following is the code for your reference:
Theme(
child: Checkbox(
value: false,
onChanged: (_) {},
),
data: ThemeData(
primarySwatch: Colors.blue,
unselectedWidgetColor: Colors.red, // Your color
),
),
I hope this helps, in case of any doubt please comment. If this answer helps you then please accept and up-vote this answer.
回答2:
You can use Theme to change the unselected widget color like given below
Theme(
data: ThemeData(unselectedWidgetColor: Colors.blue),
child: Checkbox(
...
)
)
来源:https://stackoverflow.com/questions/59651366/how-to-change-checkbox-border-color-in-flutter-by-default-it-is-showing-black