31

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 ?

vishal dharankar
  • 7,536
  • 7
  • 57
  • 93

7 Answers7

57
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).
vishal dharankar
  • 7,536
  • 7
  • 57
  • 93
kooskoos
  • 4,622
  • 1
  • 12
  • 29
23

You can do it by using side property...

side: BorderSide(color: Color(0xff585858)),
Hossein Azem
  • 331
  • 3
  • 8
Huraira Awan
  • 231
  • 2
  • 2
8

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:)

Moghaddam
  • 271
  • 5
  • 8
1

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,
                    ),
                  ),
0

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

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
0

Use side its simple.

Ex - side: BorderSide(color: Colors.red),

Dinith
  • 839
  • 14
  • 22
0
 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,
                    ),
                  ),
                ),
Mr. Tayyab MuGhal
  • 1,791
  • 2
  • 10
  • 11