CrySelectCustomWidget<T> constructor

CrySelectCustomWidget<T>(
  1. BuildContext context, {
  2. TextEditingController? controller,
  3. String? initialValueLabel,
  4. Key? key,
  5. double? width,
  6. double? padding,
  7. String? label,
  8. T? initialValue,
  9. FormFieldSetter<T>? onSaved,
  10. Function? getValueLabel,
  11. Function? getValue,
  12. required Widget popWidget,
})

Implementation

CrySelectCustomWidget(
  BuildContext context, {
  this.controller,
  this.initialValueLabel,
  Key? key,
  double? width,
  double? padding,
  String? label,
  T? initialValue,
  FormFieldSetter<T>? onSaved,
  Function? getValueLabel,
  Function? getValue,
  required Widget popWidget,
}) : super(
        key: key,
        initialValue: initialValue,
        onSaved: onSaved,
        builder: (FormFieldState<T> field) {
          final _CrySelectCustomWidgetState state = field as _CrySelectCustomWidgetState;
          return Container(
            padding: EdgeInsets.all(padding ?? 20.0),
            width: width ?? double.infinity,
            child: TextField(
              readOnly: true,
              controller: state._effectiveController,
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => popWidget),
                ).then((res) {
                  if (res == null) {
                    return;
                  }
                  String valueLabel = getValueLabel == null ? res.toString() : getValueLabel(res);
                  initialValue = getValue == null ? res.toString() : getValue(res);
                  field.didChange(initialValue);
                  state.didChangeValueLabel(valueLabel);
                });
              },
              decoration: InputDecoration(
                contentPadding: EdgeInsets.symmetric(horizontal: 10),
                labelText: label,
              ),
            ),
          );
        },
      );