import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:mnemo_cards_common/mnemo_cards_common.dart'; class DateParam extends StatelessWidget { final String title; final DateTime? initial; final Function(DateTime? v) onChanged; DateParam(this.title, this.initial, this.onChanged); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(8.0), child: Row( children: [ Text(title), SizedBox( width: 2, ), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () async { final date = await showDatePicker( context: context, initialEntryMode: DatePickerEntryMode.calendar, initialDate: initial ?? DateTime.now(), firstDate: DateTime.utc(2000), lastDate: DateTime.utc(2050), ).then((selectedDate) { // After selecting the date, display the time picker. if (selectedDate != null) { return showTimePicker( context: context, initialTime: TimeOfDay.now(), ).then((selectedTime) { // Handle the selected date and time here. if (selectedTime != null) { DateTime selectedDateTime = DateTime( selectedDate.year, selectedDate.month, selectedDate.day, selectedTime.hour, selectedTime.minute, ); return selectedDateTime; } return null; }); } return null; }); onChanged(date); }, child: Expanded( child: Text( initial?.let( (d) => '${d.year}.${d.month}.${d.day} ${d.hour}:${d.minute}', ) ?? 'No date', ), ), ), ], ), ); } }