As you can see in second image the date was deselected on hovering.
Try using this component.
class CustomDatePicker extends StatefulWidget {
const CustomDatePicker({
super.key,
});
@override
State<CustomDatePicker> createState() => _CustomDatePickerState();
}
class _CustomDatePickerState extends State<CustomDatePicker> {
OverlayEntry? _overlayEntry;
OverlayEntry _createOverlayEntry() {
if (_overlayEntry != null) {
_overlayEntry?.remove();
_overlayEntry = null;
}
final renderBox = context.findRenderObject()! as RenderBox;
final size = renderBox.size;
final offset = renderBox.localToGlobal(
Offset.zero,
ancestor: Navigator.of(context).context.findRenderObject(),
);
return OverlayEntry(
builder: (context) => Positioned(
left: offset.dx - 400,
top: offset.dy + size.height + 5.0,
width: size.width + 400,
child: Material(
color: PrimaryThemeData.get(context).primaryColor,
elevation: 8,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 2,
child: CalendarDatePicker2(
config: CalendarDatePicker2Config(
calendarType: CalendarDatePicker2Type.range,
selectedDayHighlightColor: Colors.purple[800],
centerAlignModePicker: true,
),
onDisplayedMonthChanged: (date) {},
value: [],
),
),
Flexible(
child: ListView(
padding: EdgeInsets.zero,
shrinkWrap: true,
children: [
ListTile(
title: Text(
'Today',
),
),
ListTile(
title: Text(
'Yesterday',
),
),
ListTile(
title: Text(
'This Week',
),
),
ListTile(
title: Text(
'Custom',
),
)
],
),
),
],
),
TextButton(
onPressed: () {
if (_overlayEntry != null) {
_overlayEntry?.remove();
_overlayEntry = null;
}
},
child: const Text('Apply'),
)
],
),
),
),
);
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
_overlayEntry = _createOverlayEntry();
Overlay.of(context).insert(_overlayEntry!);
},
child: FocusableActionDetector(
mouseCursor: SystemMouseCursors.click,
onFocusChange: (focus) {
if (focus) {
_overlayEntry = _createOverlayEntry();
Overlay.of(context).insert(_overlayEntry!);
} else {
_overlayEntry?.remove();
}
},
child: SizedBox(
height: 40,
width: 160,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.calendar_month_outlined,
),
const SizedBox(width: 8),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Custom Range',
),
const SizedBox(height: 4),
Text(
'Oct 11 - Nov 10',
),
],
),
const SizedBox(width: 4),
Icon(
Icons.arrow_drop_down,
),
],
),
),
),
);
}
}