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,
  String? labelPrefix,
  String? label,
  Widget? labelWidget,
  void Function(bool value)? onSaved,
  String? Function(bool value)? validator,
  bool? initialValue,
  super.enabled = true,
  super.autovalidateMode = AutovalidateMode.disabled,
  TextStyle? style,
  InputDecoration? decoration,
  EdgeInsets padding = const EdgeInsets.all(8),
  Widget? prefixIcon,
  Widget? suffixIcon,
  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
           ? (bool? value) => validator(value ?? false)
           : null,
       onSaved: enabled && onSaved != null
           ? (bool? value) => onSaved(value ?? false)
           : null,
       builder: (FormFieldState<bool> field) {
         final _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,
                       ),
                     ],
                   ),
                 ),
               ),
             ),
           ),
         );
       },
     );