CrySelectDate constructor

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

Implementation

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