Skip to content

Add backgroundColor to Checkbox and CheckboxThemeData #123386

@ValentinVignal

Description

@ValentinVignal

Use case

When a checkbox is unchecked, the background color/fill color is transparent.
It would be nice to have a way to have a parameter to change it and be able to set it in the theme.

Right now, I have to use a ColoredBox around the Checkbox in addition to a SizedBox to remove the padding of the Checkbox.
See this Stack Overflow question


I would like to set the background color of a Checkbox, like this image (unchecked check box)

image

Here is my code to achieve this at the moment:

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  var _value = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          height: 16,
          width: 16,
          child: ColoredBox(
            color: Colors.green,
            child: Checkbox(
              value: _value,
              onChanged: (value) {
                setState(() {
                  _value = value!;
                });
              },
            ),
          ),
        ),
      ),
    );
  }
}

Proposal

Add a parameter backgroundColor to Checkbox and a property backgroundColor to the CheckboxThemeData.

Metadata

Metadata

Assignees

Labels

c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions