CrySelectDate constructor

CrySelectDate(
  1. BuildContext context, {
  2. Key? key,
  3. String? value,
  4. String? label,
  5. double? width,
  6. double? padding,
  7. ValueChanged? onChange,
  8. FormFieldSetter? onSaved,
})

Implementation

CrySelectDate(
  BuildContext context, {
  Key? key,
  String? value,
  String? label,
  double? width,
  double? padding,
  ValueChanged? onChange,
  FormFieldSetter? onSaved,
}) : super(
        key: key,
        width: width,
        padding: padding,
        builder: (CryFormFieldState state) {
          return TextFormField(
            readOnly: true,
            decoration: InputDecoration(
              contentPadding: EdgeInsets.symmetric(horizontal: 10),
              labelText: label,
            ),
            controller: TextEditingController(text: value),
            onChanged: (v) {
              if (onChange != null) {
                onChange(v);
              }
            },
            onTap: () async {
              DateTime valueDt = isBlank(value) ? DateTime.now() : DateTime.parse(value!);
              final DateTime? picked = await showDatePicker(
                context: context,
                initialDate: valueDt,
                firstDate: DateTime(1900, 1),
                lastDate: DateTime(2031, 12),
              );
              if (picked != null) {
                value = formatDate(picked, [yyyy, '-', mm, '-', dd]);
              }
              state.didChange();
            },
            onSaved: onSaved,
          );
        },
      );