How to change checkbox border-color in flutter? By default, it is showing black but I want it in grey

狂风中的少年 提交于 2021-01-03 06:35:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!