Skip to content

Commit ab03e29

Browse files
Added option to select a date using controller
1 parent ceccb2b commit ab03e29

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

example/ios/Flutter/flutter_export_environment.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export "FLUTTER_BUILD_DIR=build"
77
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
88
export "FLUTTER_BUILD_NAME=1.0.0"
99
export "FLUTTER_BUILD_NUMBER=1"
10+
export "DART_DEFINES=flutter.inspector.structuredErrors%3Dtrue"
1011
export "DART_OBFUSCATION=false"
1112
export "TRACK_WIDGET_CREATION=true"
1213
export "TREE_SHAKE_ICONS=false"

lib/date_picker_widget.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class DatePickerController {
250250
curve: curve);
251251
}
252252

253-
/// This function will animate to any date that is passed as a parameter
253+
/// This function will animate to any date that is passed as an argument
254254
/// In case a date is out of range nothing will happen
255255
void animateToDate(DateTime date,
256256
{duration = const Duration(milliseconds: 500), curve = Curves.linear}) {
@@ -261,6 +261,24 @@ class DatePickerController {
261261
duration: duration, curve: curve);
262262
}
263263

264+
/// This function will animate to any date that is passed as an argument
265+
/// this will also set that date as the current selected date
266+
void setDateAndAnimate(DateTime date,
267+
{duration = const Duration(milliseconds: 500), curve = Curves.linear}) {
268+
assert(_datePickerState != null,
269+
'DatePickerController is not attached to any DatePicker View.');
270+
271+
_datePickerState!._controller.animateTo(_calculateDateOffset(date),
272+
duration: duration, curve: curve);
273+
274+
if (date.compareTo(_datePickerState!.widget.startDate) >= 0 &&
275+
date.compareTo(_datePickerState!.widget.startDate.add(
276+
Duration(days: _datePickerState!.widget.daysCount))) <= 0) {
277+
// date is in the range
278+
_datePickerState!._currentDate = date;
279+
}
280+
}
281+
264282
/// Calculate the number of pixels that needs to be scrolled to go to the
265283
/// date provided in the argument
266284
double _calculateDateOffset(DateTime date) {

0 commit comments

Comments
 (0)