Checkbox

A material design checkbox.

The checkbox itself does not maintain any state. Instead, when the state of the checkbox changes, the widget calls the onChanged callback. Most widgets that use a checkbox will listen for the onChanged callback and rebuild the checkbox with a new value to update the visual appearance of the checkbox.

Properties

activeColor

The color to use when this checkbox is checked. It specifies the background color, the color that surrounds the tick mark.

checkColor

The color to use for the check icon when this checkbox is checked.

onChanged

Called when the value of the checkbox should change.

tristate

This property specifies if the checkbox should maintain three state. If this property is set to true, the checkbox's value can be true, false, or null.

Checkbox displays a dash when its value is null.

If tristate is false (the default), value must not be null.

value

Whether this checkbox is checked. This property is used to provide the checkbox a value. If true, the checkbox will be selected, if false, the checkbox will be unselected and if the value is null(tristate is true), the checkbox will contain a dashed mark.

Example

class _MyWidgetState extends State<MyWidget> {
  bool rememberMe = false;

  void _onRememberMeChanged(bool newValue) => setState(() {
    rememberMe = newValue;

    if (rememberMe) {
      // TODO: Here goes your functionality that remembers the user.
    } else {
      // TODO: Forget the user
    }
  });

  @override
  Widget build(BuildContext context) {
    return Checkbox(
      value: rememberMe,
      onChanged: _onRememberMeChanged
    );
  }
}