35

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 ?

2
  • AFAIK,Container has border property. Commented Dec 18, 2019 at 7:24
  • Tried it but I was required to adjust the container as per the size of checkbox I didn't find it elegant Commented Dec 21, 2019 at 18:12

8 Answers 8

59
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).
Sign up to request clarification or add additional context in comments.

2 Comments

Glad, I was able to help!
It should be mentioned, that the Checkbox requires the onChanged parameter, otherwise the inactive colors are used and ThemeData does not bring any changes
32

You can do it by using side property...

side: BorderSide(color: Color(0xff585858)),

1 Comment

Simplest answer, thanks! The side property has preference over ThemeData and CheckboxThemeData.
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:)

Comments

2

You could change the border color using below code.

   Checkbox(
      value: _isChecked,
      onChanged: (bool value) => setState(() => _isChecked = value),
      side: BorderSide(color: Colors.green, width: 2.0),
    )

Comments

1

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

1 Comment

ThemeData is a much more effective way of setting the border.
1
 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,
                    ),
                  ),
                ),

Comments

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

Comments

0

Use side its simple.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.