Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add diameterRatio and squeeze parameters #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -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 =
Expand Down Expand Up @@ -78,27 +80,25 @@ class _WidgetPageState extends State<WidgetPage> {
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,
),

),
),
),
),
);
}
}


2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lib/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Widget> 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);
Expand Down Expand Up @@ -153,6 +157,8 @@ class DatePicker {
content: Container(
width: 300,
child: DatePickerWidget(
squeeze: squeeze,
diameterRatio: diameterRatio,
firstDate: firstDate,
lastDate: lastDate,
initialDate: initialDate,
Expand Down
22 changes: 15 additions & 7 deletions lib/widget/date_picker_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -40,17 +42,21 @@ class DatePickerWidget extends StatefulWidget {
final DateVoidCallback? onCancel;
final DateValueCallback? onChange, onConfirm;
final bool looping;
final double squeeze;
final double diameterRatio;

@override
State<StatefulWidget> createState() =>
_DatePickerWidgetState(this.firstDate, this.lastDate, this.initialDate);
}

class _DatePickerWidgetState extends State<DatePickerWidget> {
late DateTime _minDateTime, _maxDateTime;
late DateTime _minDateTime, _maxDateTime;
int? _currYear, _currMonth, _currDay;
List<int>? _yearRange, _monthRange, _dayRange;
FixedExtentScrollController? _yearScrollCtrl, _monthScrollCtrl, _dayScrollCtrl;
FixedExtentScrollController? _yearScrollCtrl,
_monthScrollCtrl,
_dayScrollCtrl;

late Map<String, FixedExtentScrollController?> _scrollCtrlMap;
late Map<String, List<int>?> _valueRangeMap;
Expand All @@ -75,15 +81,16 @@ class _DatePickerWidgetState extends State<DatePickerWidget> {

// 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 =
Expand Down Expand Up @@ -193,9 +200,10 @@ class _DatePickerWidgetState extends State<DatePickerWidget> {
BoxDecoration(color: widget.pickerTheme!.backgroundColor),
child: CupertinoPicker(
backgroundColor: widget.pickerTheme!.backgroundColor,
selectionOverlay: Container(),
scrollController: scrollCtrl,
squeeze: 0.95,
diameterRatio: 1.5,
squeeze: widget.squeeze,
diameterRatio: widget.diameterRatio,
itemExtent: widget.pickerTheme!.itemHeight,
onSelectedItemChanged: valueChanged,
looping: widget.looping,
Expand Down