why don't you do focus center when date clicked?
Opened this issue · 1 comments
gamcho3 commented
Is your feature request related to a problem? Please describe.
I want to focus center when date clicked and focus initialSelectedDate when entered page.
alierdogan7 commented
Make a stateful widget and then in initState
function call DatePickerController
's animation methods such as animateToDate
, animateToSelection
, etc.
For example, the code snippet below initializes a date picker and then immediately animates to two days back (in order for the selected date to appear at center):
class _HorizontalDatePickerState extends ConsumerState<HorizontalDatePicker> {
final controller = DatePickerController();
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) => controller.animateToDate(widget.selectedDate.subtract(Duration(days: 2))));
}
@override
Widget build(BuildContext context) {
return DatePicker(
widget.startDate,
initialSelectedDate: widget.selectedDate,
selectionColor: Theme.of(context).colorScheme.primary,
selectedTextColor: Colors.white,
locale: ref.watch(appLocaleProvider.notifier).getLocaleString(),
onDateChange: (date) => widget.onDateChange(date),
controller: controller,
);
}
}