toWidget method

  1. @override
Widget toWidget(
  1. BuildContext context,
  2. String group,
  3. DateTime? value
)
override

Builds the current field into a Widget to be used for input in the side panel.

Implementation

@override
Widget toWidget(BuildContext context, String group, DateTime? value) {
  return TextFormField(
    initialValue: (value ?? initialValue)?.toSimpleFormat(),
    keyboardType: TextInputType.datetime,
    decoration: InputDecoration(
      suffixIcon: IconButton(
        icon: const Icon(Icons.calendar_today_rounded),
        onPressed: () async {
          final dateTime = await showDateTimePicker(
            context,
            value ?? initialValue,
          );

          if (dateTime == null) return;

          updateField(
            context,
            group,
            dateTime,
          );
        },
      ),
    ),
    onChanged: (value) => updateField(
      context,
      group,
      codec.toValue(value) ?? initialValue ?? DateTime.now(),
    ),
  );
}