From a94602db31dcec71c7c9e2c3d5943c529ad381b9 Mon Sep 17 00:00:00 2001 From: Maxim Ilyshchenko Date: Wed, 17 Mar 2021 22:58:31 +0300 Subject: [PATCH 1/2] add diameterRatio and squeeze parameters --- example/lib/main.dart | 24 ++++++++++++------------ example/pubspec.lock | 2 +- lib/date_picker.dart | 10 ++++++++-- lib/widget/date_picker_widget.dart | 21 ++++++++++++++------- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index fef1fa4..9f60d94 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -12,10 +12,10 @@ class MyApp extends StatelessWidget { theme: ThemeData(primarySwatch: Colors.blue), // home: DateTesting(), home: Scaffold( - appBar: AppBar( - title: Text('Holo Datepicker Example'), - ), - body: MyHomePage(), + appBar: AppBar( + title: Text('Holo Datepicker Example'), + ), + body: MyHomePage(), ), debugShowCheckedModeBanner: false, ); @@ -40,6 +40,8 @@ class MyHomePage extends StatelessWidget { dateFormat: "dd-MMMM-yyyy", locale: DateTimePickerLocale.en_us, looping: true, + diameterRatio: 1.5, + squeeze: 0.95, ); final snackBar = @@ -78,21 +80,21 @@ class _WidgetPageState extends State { child: DatePickerWidget( looping: false, // default is not looping firstDate: DateTime.now(), //DateTime(1960), - // lastDate: DateTime(2002, 1, 1), + // lastDate: DateTime(2002, 1, 1), // initialDate: DateTime.now(),// DateTime(1994), - dateFormat: - "MM-dd(E)", - // "dd-MMMM-yyyy", - // locale: DatePicker.localeFromString('he'), + dateFormat: "MM-dd(E)", + // "dd-MMMM-yyyy", + // locale: DatePicker.localeFromString('he'), onChange: (DateTime newDate, _) { _selectedDate = newDate; print(_selectedDate); }, + diameterRatio: 1.5, + squeeze: 0.95, pickerTheme: DateTimePickerTheme( itemTextStyle: TextStyle(color: Colors.black, fontSize: 19), dividerColor: Colors.blue, ), - ), ), ), @@ -100,5 +102,3 @@ class _WidgetPageState extends State { ); } } - - diff --git a/example/pubspec.lock b/example/pubspec.lock index 6869f40..3c4c30e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -75,7 +75,7 @@ packages: path: ".." relative: true source: path - version: "0.3.2" + version: "1.0.0-nullsafety.0" flutter_test: dependency: "direct dev" description: flutter diff --git a/lib/date_picker.dart b/lib/date_picker.dart index 36139b4..4d6a3e2 100644 --- a/lib/date_picker.dart +++ b/lib/date_picker.dart @@ -105,16 +105,20 @@ class DatePicker { String? cancelText, bool looping: false, bool reverse: false, + double squeeze = 0.95, + double diameterRatio = 1.5, }) { DateTime? _selectedDate = initialDate; final List listButtonActions = [ - TextButton(style: TextButton.styleFrom(primary:textColor), + TextButton( + style: TextButton.styleFrom(primary: textColor), child: Text(confirmText ?? "OK"), onPressed: () { Navigator.pop(context, _selectedDate); }, ), - TextButton(style: TextButton.styleFrom(primary:textColor), + TextButton( + style: TextButton.styleFrom(primary: textColor), child: Text(cancelText ?? "Cancel"), onPressed: () { Navigator.pop(context); @@ -153,6 +157,8 @@ class DatePicker { content: Container( width: 300, child: DatePickerWidget( + squeeze: squeeze, + diameterRatio: diameterRatio, firstDate: firstDate, lastDate: lastDate, initialDate: initialDate, diff --git a/lib/widget/date_picker_widget.dart b/lib/widget/date_picker_widget.dart index f363f60..e1c396a 100644 --- a/lib/widget/date_picker_widget.dart +++ b/lib/widget/date_picker_widget.dart @@ -26,6 +26,8 @@ class DatePickerWidget extends StatefulWidget { this.onChange, this.onConfirm, this.looping: false, + this.squeeze: 0.95, + this.diameterRatio: 1.5, }) : super(key: key) { DateTime minTime = firstDate ?? DateTime.parse(DATE_PICKER_MIN_DATETIME); DateTime maxTime = lastDate ?? DateTime.parse(DATE_PICKER_MAX_DATETIME); @@ -40,6 +42,8 @@ class DatePickerWidget extends StatefulWidget { final DateVoidCallback? onCancel; final DateValueCallback? onChange, onConfirm; final bool looping; + final double squeeze; + final double diameterRatio; @override State createState() => @@ -47,10 +51,12 @@ class DatePickerWidget extends StatefulWidget { } class _DatePickerWidgetState extends State { - late DateTime _minDateTime, _maxDateTime; + late DateTime _minDateTime, _maxDateTime; int? _currYear, _currMonth, _currDay; List? _yearRange, _monthRange, _dayRange; - FixedExtentScrollController? _yearScrollCtrl, _monthScrollCtrl, _dayScrollCtrl; + FixedExtentScrollController? _yearScrollCtrl, + _monthScrollCtrl, + _dayScrollCtrl; late Map _scrollCtrlMap; late Map?> _valueRangeMap; @@ -75,15 +81,16 @@ class _DatePickerWidgetState extends State { // limit the range of month this._monthRange = _calcMonthRange(); - this._currMonth = min(max(_monthRange!.first, _currMonth!), _monthRange!.last); + this._currMonth = + min(max(_monthRange!.first, _currMonth!), _monthRange!.last); // limit the range of day this._dayRange = _calcDayRange(); this._currDay = min(max(_dayRange!.first, _currDay!), _dayRange!.last); // create scroll controller - _yearScrollCtrl = - FixedExtentScrollController(initialItem: _currYear! - _yearRange!.first); + _yearScrollCtrl = FixedExtentScrollController( + initialItem: _currYear! - _yearRange!.first); _monthScrollCtrl = FixedExtentScrollController( initialItem: _currMonth! - _monthRange!.first); _dayScrollCtrl = @@ -194,8 +201,8 @@ class _DatePickerWidgetState extends State { child: CupertinoPicker( backgroundColor: widget.pickerTheme!.backgroundColor, scrollController: scrollCtrl, - squeeze: 0.95, - diameterRatio: 1.5, + squeeze: widget.squeeze, + diameterRatio: widget.diameterRatio, itemExtent: widget.pickerTheme!.itemHeight, onSelectedItemChanged: valueChanged, looping: widget.looping, From 1754716d5a9ac8118b80c77221a9a6c35038f5a1 Mon Sep 17 00:00:00 2001 From: Maxim <58557830+perpointt@users.noreply.github.com> Date: Sun, 28 Mar 2021 21:25:15 +0300 Subject: [PATCH 2/2] Update date_picker_widget.dart --- lib/widget/date_picker_widget.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/widget/date_picker_widget.dart b/lib/widget/date_picker_widget.dart index e1c396a..bd935b7 100644 --- a/lib/widget/date_picker_widget.dart +++ b/lib/widget/date_picker_widget.dart @@ -200,6 +200,7 @@ class _DatePickerWidgetState extends State { BoxDecoration(color: widget.pickerTheme!.backgroundColor), child: CupertinoPicker( backgroundColor: widget.pickerTheme!.backgroundColor, + selectionOverlay: Container(), scrollController: scrollCtrl, squeeze: widget.squeeze, diameterRatio: widget.diameterRatio,