BoolField constructor

BoolField({
  1. ValueNotifier<bool>? controller,
  2. FocusNode? focusNode,
  3. dynamic onChanged(
    1. bool value
    )?,
  4. String? labelPrefix,
  5. String? label,
  6. Widget? labelWidget,
  7. void onSaved(
    1. bool value
    )?,
  8. String? validator(
    1. bool value
    )?,
  9. bool? initialValue,
  10. bool enabled = true,
  11. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  12. TextStyle? style,
  13. InputDecoration? decoration,
  14. EdgeInsets padding = const EdgeInsets.all(8),
  15. Widget? prefixIcon,
  16. Widget? suffixIcon,
  17. EdgeInsets? contentPadding,
  18. int? sizeExtraSmall,
  19. int? sizeSmall,
  20. int? sizeMedium,
  21. int? sizeLarge,
  22. int? sizeExtraLarge,
  23. double? minHeight,
  24. 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,
                       ),
                     ],
                   ),
                 ),
               ),
             ),
           ),
         );
       },
     );