datePickerEntry method

Widget datePickerEntry({
  1. String title = 'Date',
  2. String subTitle = 'the date',
  3. dynamic onChanged(
    1. DateTime?
    )?,
  4. DateTime? firstDate,
  5. DateTime? lastDate,
  6. Function? onPressed,
  7. DateTime? defaultValue,
})

Implementation

Widget datePickerEntry({
  String title = 'Date',
  String subTitle = 'the date',
  Function(DateTime?)? onChanged,
  DateTime? firstDate,
  DateTime? lastDate,
  Function? onPressed,
  DateTime? defaultValue,
}) {
  return formEntry(
    title: title,
    subTitle: subTitle,
    inputWidget: TertiaryFlatButton(
      onPressed: () async {
        onPressed?.call();
        final DateTime? pickedDate = await showDatePicker(
          context: context,
          initialDate: defaultValue ?? firstDate,
          firstDate: firstDate ?? DateTime(2021),
          lastDate: lastDate ?? DateTime(2101),
        );
        onChanged?.call(pickedDate);
      },
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const Icon(Icons.watch_later_outlined),
          SizedBox(width: smallPadding),
          Text(
            defaultValue != null
                ? '${defaultValue.day.toString().padLeft(2, '0')}-${defaultValue.month.toString().padLeft(2, '0')}-${defaultValue.year}'
                : 'Select date',
            style: Theme.of(context).textTheme.bodyLarge,
          ),
        ],
      ),
    ),
  );
}