如何更改Flutter复选框的厚度

huangapple go评论59阅读模式
英文:

How to change the thickness of flutter checkbox

问题

After searching, I found a way to change the colors of the checkbox, but I did not find a way to change the thickness.

Is there any way other than using custom checkbox?

checkboxTheme: CheckboxThemeData(
  checkColor: MaterialStateProperty.all(kWhiteColor),
  fillColor: MaterialStateColor.resolveWith((states) {
    if (states.contains(MaterialState.selected)) {
      return kPrimaryColor; // the color when checkbox is selected;
    }
    return Colors.grey
        .withOpacity(0.4); //the color when checkbox is unselected;
  }),

Thanks.

英文:

After searching, I found a way to change the colors of the checkbox, but I did not find a way to change the thickness

Is there any way other than using custom checkbox

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

 checkboxTheme: CheckboxThemeData(
        checkColor: MaterialStateProperty.all(kWhiteColor),
        fillColor: MaterialStateColor.resolveWith((states) {
          if (states.contains(MaterialState.selected)) {
            return kPrimaryColor; // the color when checkbox is selected;
          }
          return Colors.grey
              .withOpacity(0.4); //the color when checkbox is unselected;
        }),

<!-- end snippet -->

thanks

答案1

得分: 0

在Flutter中,CheckBox小部件带有一个名为side的属性。使用side属性,可以轻松更改复选框的样式、颜色、宽度等。

代码段示例:

Checkbox(
    side: MaterialStateBorderSide.resolveWith(
      (Set<MaterialState> states) {
        if (states.contains(MaterialState.selected)) {
          return const BorderSide(width: 3, color: Colors.red);
        }
        return const BorderSide(width: 2, color: Colors.green);
      },
    ),
    value: checkBoxValue,
    onChanged: (bool? updatedValue) {
      setState(() {
        checkBoxValue = updatedValue!;
      });
    }
)
英文:

In flutter, the checkBox widget comes with a property named side .
Using the side property, one can easily change the check box's style, color, width, etc.

Code snippet example:

Checkbox(
        side: MaterialStateBorderSide.resolveWith(
          (Set&lt;MaterialState&gt; states) {
            if (states.contains(MaterialState.selected)) {
              return const BorderSide(width: 3, color: Colors.red);
            }
            return const BorderSide(width: 2, color: Colors.green);
          },
        ),
        value: checkBoxValue,
        onChanged: (bool? updatedValue) {
          setState(() {
            checkBoxValue = updatedValue!;
          });
        })

huangapple
  • 本文由 发表于 2023年2月6日 18:11:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359905.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定