Rendering fields

Boolean fields

Switch takes the setter as it is; Checkbox needs it adapted from bool? — and both disable themselves when it is null.

field.getValueSetter() is a ValueSetter<bool>?: the field's setValue while the field is writable, null while it is read-only. Switch.onChanged has exactly that type, so it goes straight in. Checkbox.onChanged takes a bool?, so adapt it.

boolean_input.dartidle
Source3 files
checkbox_input.dart
class _CheckboxInput extends StatelessWidget {
  const _CheckboxInput({required this.field, required this.label});

  final AdvancedBooleanFieldController<String> field;
  final String label;

  @override
  Widget build(BuildContext context) {
    return AdvancedFieldBuilder<bool, String>(
      field: field,
      builder: (context, state, _) {
        final setter = field.getValueSetter(); // null while read-only
        return CheckboxListTile(
          value: state.value,
          onChanged: setter == null ? null : (v) => setter(v ?? false),
          title: Text(label),
          // A boolean has no errorText slot: show the error yourself.
          subtitle: state.error == null ? null : Text(state.error!),
          controlAffinity: ListTileControlAffinity.leading,
        );
      },
    );
  }
}
DocsActions is a shorthand these docs define, not part of the package. See Rendering fields for the widget code an app writes.

A boolean has no errorText slot, so its error is rendered next to it — as the tile's subtitle above, or in an InputDecorator around the control. The rule itself is the built-in mustBeTrue.