BoolField constructor
BoolField({
- ValueNotifier<
bool> ? controller, - FocusNode? focusNode,
- dynamic onChanged(
- bool value
- String? labelPrefix,
- String? label,
- Widget? labelWidget,
- void onSaved(
- bool value
- String? validator(
- bool value
- bool? initialValue,
- bool enabled = true,
- AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- TextStyle? style,
- InputDecoration? decoration,
- EdgeInsets padding = const EdgeInsets.all(8),
- Widget? prefixIcon,
- Widget? suffixIcon,
- EdgeInsets? contentPadding,
- int? sizeExtraSmall,
- int? sizeSmall,
- int? sizeMedium,
- int? sizeLarge,
- int? sizeExtraLarge,
- double? minHeight,
- Key? key,
Implementation
BoolField({
this.controller,
this.focusNode,
this.onChanged,
final String? labelPrefix,
final String? label,
final Widget? labelWidget,
final void Function(bool value)? onSaved,
final String? Function(bool value)? validator,
final bool? initialValue,
super.enabled = true,
super.autovalidateMode = AutovalidateMode.disabled,
final TextStyle? style,
final InputDecoration? decoration,
final EdgeInsets padding = const EdgeInsets.all(8),
final Widget? prefixIcon,
final Widget? suffixIcon,
final EdgeInsets? contentPadding,
super.sizeExtraSmall,
super.sizeSmall,
super.sizeMedium,
super.sizeLarge,
super.sizeExtraLarge,
super.minHeight,
super.key,
}) : assert(
initialValue == null || controller == null,
'initialValue or controller must be null.',
),
assert(
label == null || labelWidget == null,
'label or labelWidget must be null.',
),
super(
initialValue: controller?.value ?? initialValue,
validator: enabled && validator != null
? (final bool? value) => validator(value ?? false)
: null,
onSaved: enabled && onSaved != null
? (final bool? value) => onSaved(value ?? false)
: null,
builder: (final FormFieldState<bool> field) {
_BoolFieldState state = field as _BoolFieldState;
final ThemeData theme = Theme.of(state.context);
final bool hasFocus = state._effectiveFocusNode.hasFocus;
final Color? color = enabled
? hasFocus
? theme.colorScheme.primary
: null
: theme.disabledColor;
final TextStyle? effectiveStyle =
(style ??
theme.textTheme.titleMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
))
?.copyWith(color: color);
final InputDecoration effectiveDecoration =
(decoration ??
InputDecoration(
border: const OutlineInputBorder(),
counterText: '',
contentPadding:
contentPadding ??
const EdgeInsets.symmetric(horizontal: 8),
prefixIcon: prefixIcon,
suffixIcon: suffixIcon,
))
.applyDefaults(theme.inputDecorationTheme)
.copyWith(enabled: enabled, errorText: state.errorText);
return Padding(
padding: padding,
child: Focus(
focusNode: state._effectiveFocusNode,
canRequestFocus: enabled,
skipTraversal: !enabled,
child: MouseRegion(
cursor: enabled
? SystemMouseCursors.click
: SystemMouseCursors.basic,
onEnter: (_) => state.hovering(enter: true),
onExit: (_) => state.hovering(enter: false),
child: GestureDetector(
onTap: enabled ? state._handleTap : null,
child: InputDecorator(
decoration: effectiveDecoration,
isFocused: hasFocus,
isHovering: state._isHovering,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
labelWidget ??
Text(
<String?>[
labelPrefix,
label,
].nonNulls.join(' - '),
style: effectiveStyle,
),
Switch(
focusNode: state.disabledFocusNode,
padding: EdgeInsets.zero,
value: state.value ?? false,
onChanged: enabled
? (_) => state._handleTap()
: null,
),
],
),
),
),
),
),
);
},
);