Flutter - CheckboxListTile - 边框颜色为白色

4

我不知道如何改变复选框边框的颜色并使文本更接近。以下是我的代码和我想实现的图像。

谢谢!

进入图像描述

CheckboxListTile(
                  title: const Text('Remember Me'),
                  value: _isSelected,
                  onChanged: (bool value) {
                    setState(() {
                      _isSelected = value;
                    });
                  },
                  controlAffinity: ListTileControlAffinity.leading,
                ),

当使用 CheckboxListTile 时,您无法控制这些属性。 - pskink
6个回答

13

尝试这个解决方案:

Theme(
    data: ThemeData(unselectedWidgetColor: Colors.white),
    child: CheckboxListTile(....),
    )

这个可以工作,但是列表瓷砖的文本会改变。 - Barry

1
如果有人试图更改复选框列表瓷砖的边框,而不是复选框本身。
CheckboxListTile(
  title: const Text('text'),
  shape: RoundedRectangleBorder(
  borderRadius: BorderRadius.circular(20.0), // Optionally
    side: const BorderSide(color: Colors.pink),
  ),
  value: true,
  onChanged: (_) {},
)

让它看起来像这样。

enter image description here


1
这两个属性检查颜色和活动颜色,帮助您更改复选框的颜色。为了将文本移近,您可以使用 Container 或 Row:您可以使用具有主轴对齐的行。

1

您可以覆盖您的主题

Theme(
  data: Theme.of(context).copyWith(
    checkboxTheme: Theme.of(context).checkboxTheme.copyWith(
          fillColor: MaterialStateProperty.resolveWith(
            (_) => !isDisabled
                ? Colors.white
                : Theme.of(context).disabledColor,
          ),
        ),
  ),
  child: CheckboxListTile(
    onChanged: onChanged,
    ...
    enabled: !isDisabled,
    dense: true,
  ),
)

1
使用side属性来改变复选框在未选择时的颜色和宽度。
CheckboxListTile(
    side: const BorderSide(color: Colors.green),
),

enter image description here


-1

你可以在行内使用复选框

Row(children:[Checkbox(...), Text(...)]);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接