CheckFormFiled constructor

CheckFormFiled({
  1. Key? key,
  2. Widget? label,
  3. FormFieldSetter<bool>? onSaved,
  4. bool? enabled,
  5. MaterialStateProperty<Color?>? fillColor,
  6. Color? checkColor,
})

Implementation

CheckFormFiled({
  Key? key,

  /// Typically an [Text] for label
  Widget? label,
  FormFieldSetter<bool>? onSaved,
  bool? enabled,
  MaterialStateProperty<Color?>? fillColor,
  Color? checkColor,
}) : super(
        key: key,
        onSaved: onSaved,
        initialValue: false,
        enabled: enabled ?? true,
        builder: (FormFieldState<bool> field) {
          _CheckFormFieldState state = field as _CheckFormFieldState;
          return Focus(
            canRequestFocus: true,
            focusNode: state._focusNode,
            child: GestureDetector(
              // borderRadius: _formFieldBorderRadius, // 这里长按的阴影部分和显示部分倒角一致
              onTap: () {
                if (state._focusNode.hasFocus) {
                  state._focusNode.unfocus();
                } else {
                  state._focusNode.requestFocus(); // 获得焦点
                }
              },
              child: DecoratedBox(
                decoration: BoxDecoration(
                  borderRadius: _formFieldBorderRadius,
                  border: Border.all(
                      color: state._focused
                          ? Theme.of(state.context).primaryColor
                          : Colors.grey,
                      width: state._focused ? 2.0 : 1.0),
                ),
                child: Container(
                  padding: const EdgeInsets.symmetric(
                      horizontal: 10.0, vertical: 8.0),
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      label ??
                          Text(
                            "",
                            style: Theme.of(state.context)
                                .dialogTheme
                                .contentTextStyle,
                          ),
                      Checkbox(
                        value: state.checkable,
                        splashRadius: 5.0,
                        onChanged: (value) {
                          field.checkable = value!;
                        },
                      ),
                    ],
                  ),
                ),
              ),
            ),
          );
        },
      );