Skip to content

Commit 290ed5a

Browse files
author
Liu Yanbo
committed
add Russian
1 parent 0354656 commit 290ed5a

11 files changed

+143
-55
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
## [1.0.4] - add Dutch in readme
1717
## [1.0.5] - add max/min time limit for Date Picker, add theme
1818
## [1.0.6] - add comments
19-
## [1.0.7] - fix max/min time for datetime type picker
19+
## [1.0.7] - fix max/min time for datetime type picker
20+
## [1.0.8] - add Russian

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
# flutter_datetime_picker
1+
# Flutter Datetime Picker
22

33
[![Pub](https://img.shields.io/pub/v/flutter_datetime_picker.svg?style=plastic)](https://pub.dartlang.org/packages/flutter_datetime_picker)
44

55
A flutter date time picker inspired by [flutter-cupertino-date-picker](https://github.com/wuzhendev/flutter-cupertino-date-picker)
66

7-
you can choose date / time / date&time in English, Dutch and Chinese, and you can also custom your own picker content
7+
you can choose date / time / date&time in English, Dutch, Chinese and Russian
88

9+
and you can also custom your own picker content
910

10-
| Date picker | Time picker | Date & Time picker (Chinese) | Date & Time picker (English-America)|Date & Time picker (Dutch)|
11-
| ------- | ------- | ------- | ------- |------- |
12-
|![]( screen_date.png)|![]( screen_time.png)|![]( screen_datetime_chinese.png)|![]( screen_datetime_english.png)|![]( screen_datetime_dutch.png)|
11+
12+
| Date picker | Time picker | Date & Time picker (Chinese) |
13+
| ------- | ------- | ------- |
14+
| ![]( screen_date.png) | ![]( screen_time.png) | ![]( screen_datetime_chinese.png) |
15+
16+
| Date & Time picker (Chinese) | Date & Time picker (America) | Date & Time picker (Dutch) | Date & Time picker (Russian) |
17+
| ------- | ------- | ------- | ------- |
18+
|![]( screen_datetime_chinese.png)|![]( screen_datetime_english.png)|![]( screen_datetime_dutch.png)|![]( screen_datetime_russian.png)|
1319

1420
## Usage
1521
```

example/ios/Runner.xcodeproj/project.pbxproj

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
11-
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
1211
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1312
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1413
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -40,7 +39,6 @@
4039
/* Begin PBXFileReference section */
4140
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4241
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
43-
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
4442
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4543
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4644
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@@ -73,7 +71,6 @@
7371
9740EEB11CF90186004384FC /* Flutter */ = {
7472
isa = PBXGroup;
7573
children = (
76-
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
7774
3B80C3931E831B6300D905FE /* App.framework */,
7875
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
7976
9740EEBA1CF902C7004384FC /* Flutter.framework */,
@@ -190,7 +187,6 @@
190187
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
191188
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
192189
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
193-
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
194190
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
195191
);
196192
runOnlyForDeploymentPostprocessing = 0;

example/lib/main.dart

+33-8
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ class HomePage extends StatelessWidget {
3535
maxTime: DateTime(2019, 6, 7),
3636
theme: DatePickerTheme(
3737
backgroundColor: Colors.blue,
38-
itemStyle: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
39-
doneStyle: TextStyle(color: Colors.white, fontSize: 16)),
38+
itemStyle: TextStyle(
39+
color: Colors.white, fontWeight: FontWeight.bold),
40+
doneStyle:
41+
TextStyle(color: Colors.white, fontSize: 16)),
4042
onChanged: (date) {
4143
print('change $date');
4244
}, onConfirm: (date) {
@@ -49,7 +51,8 @@ class HomePage extends StatelessWidget {
4951
)),
5052
FlatButton(
5153
onPressed: () {
52-
DatePicker.showTimePicker(context, showTitleActions: true, onChanged: (date) {
54+
DatePicker.showTimePicker(context, showTitleActions: true,
55+
onChanged: (date) {
5356
print('change $date');
5457
}, onConfirm: (date) {
5558
print('confirm $date');
@@ -61,19 +64,23 @@ class HomePage extends StatelessWidget {
6164
)),
6265
FlatButton(
6366
onPressed: () {
64-
DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
67+
DatePicker.showDateTimePicker(context, showTitleActions: true,
68+
onChanged: (date) {
6569
print('change $date');
6670
}, onConfirm: (date) {
6771
print('confirm $date');
68-
}, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.zh);
72+
},
73+
currentTime: DateTime(2008, 12, 31, 23, 12, 34),
74+
locale: LocaleType.zh);
6975
},
7076
child: Text(
7177
'show date time picker (Chinese)',
7278
style: TextStyle(color: Colors.blue),
7379
)),
7480
FlatButton(
7581
onPressed: () {
76-
DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
82+
DatePicker.showDateTimePicker(context, showTitleActions: true,
83+
onChanged: (date) {
7784
print('change $date');
7885
}, onConfirm: (date) {
7986
print('confirm $date');
@@ -85,16 +92,34 @@ class HomePage extends StatelessWidget {
8592
)),
8693
FlatButton(
8794
onPressed: () {
88-
DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
95+
DatePicker.showDateTimePicker(context, showTitleActions: true,
96+
onChanged: (date) {
8997
print('change $date');
9098
}, onConfirm: (date) {
9199
print('confirm $date');
92-
}, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.nl);
100+
},
101+
currentTime: DateTime(2008, 12, 31, 23, 12, 34),
102+
locale: LocaleType.nl);
93103
},
94104
child: Text(
95105
'show date time picker (Dutch)',
96106
style: TextStyle(color: Colors.blue),
97107
)),
108+
FlatButton(
109+
onPressed: () {
110+
DatePicker.showDateTimePicker(context, showTitleActions: true,
111+
onChanged: (date) {
112+
print('change $date');
113+
}, onConfirm: (date) {
114+
print('confirm $date');
115+
},
116+
currentTime: DateTime(2008, 12, 31, 23, 12, 34),
117+
locale: LocaleType.ru);
118+
},
119+
child: Text(
120+
'show date time picker (Russian)',
121+
style: TextStyle(color: Colors.blue),
122+
)),
98123
],
99124
),
100125
),

lib/flutter_datetime_picker.dart

+39-22
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ class DatePicker {
3636
onConfirm: onConfirm,
3737
locale: locale,
3838
theme: theme,
39-
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
39+
barrierLabel:
40+
MaterialLocalizations.of(context).modalBarrierDismissLabel,
4041
pickerModel: DatePickerModel(
41-
currentTime: currentTime, maxTime: maxTime, minTime: minTime, locale: locale)));
42+
currentTime: currentTime,
43+
maxTime: maxTime,
44+
minTime: minTime,
45+
locale: locale)));
4246
}
4347

4448
///
@@ -61,8 +65,10 @@ class DatePicker {
6165
onConfirm: onConfirm,
6266
locale: locale,
6367
theme: theme,
64-
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
65-
pickerModel: TimePickerModel(currentTime: currentTime, locale: locale)));
68+
barrierLabel:
69+
MaterialLocalizations.of(context).modalBarrierDismissLabel,
70+
pickerModel:
71+
TimePickerModel(currentTime: currentTime, locale: locale)));
6672
}
6773

6874
///
@@ -85,8 +91,10 @@ class DatePicker {
8591
onConfirm: onConfirm,
8692
locale: locale,
8793
theme: theme,
88-
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
89-
pickerModel: DateTimePickerModel(currentTime: currentTime, locale: locale)));
94+
barrierLabel:
95+
MaterialLocalizations.of(context).modalBarrierDismissLabel,
96+
pickerModel:
97+
DateTimePickerModel(currentTime: currentTime, locale: locale)));
9098
}
9199

92100
///
@@ -109,7 +117,8 @@ class DatePicker {
109117
onConfirm: onConfirm,
110118
locale: locale,
111119
theme: theme,
112-
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
120+
barrierLabel:
121+
MaterialLocalizations.of(context).modalBarrierDismissLabel,
113122
pickerModel: pickerModel));
114123
}
115124
}
@@ -152,13 +161,14 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
152161
@override
153162
AnimationController createAnimationController() {
154163
assert(_animationController == null);
155-
_animationController = BottomSheet.createAnimationController(navigator.overlay);
164+
_animationController =
165+
BottomSheet.createAnimationController(navigator.overlay);
156166
return _animationController;
157167
}
158168

159169
@override
160-
Widget buildPage(
161-
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
170+
Widget buildPage(BuildContext context, Animation<double> animation,
171+
Animation<double> secondaryAnimation) {
162172
Widget bottomSheet = new MediaQuery.removePadding(
163173
context: context,
164174
removeTop: true,
@@ -179,7 +189,11 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
179189

180190
class _DatePickerComponent extends StatefulWidget {
181191
_DatePickerComponent(
182-
{Key key, @required this.route, this.onChanged, this.locale, this.pickerModel});
192+
{Key key,
193+
@required this.route,
194+
this.onChanged,
195+
this.locale,
196+
this.pickerModel});
183197

184198
final DateChangedCallback onChanged;
185199

@@ -205,12 +219,12 @@ class _DatePickerState extends State<_DatePickerComponent> {
205219
}
206220

207221
void refreshScrollOffset() {
208-
leftScrollCtrl =
209-
new FixedExtentScrollController(initialItem: widget.pickerModel.currentLeftIndex());
210-
middleScrollCtrl =
211-
new FixedExtentScrollController(initialItem: widget.pickerModel.currentMiddleIndex());
212-
rightScrollCtrl =
213-
new FixedExtentScrollController(initialItem: widget.pickerModel.currentRightIndex());
222+
leftScrollCtrl = new FixedExtentScrollController(
223+
initialItem: widget.pickerModel.currentLeftIndex());
224+
middleScrollCtrl = new FixedExtentScrollController(
225+
initialItem: widget.pickerModel.currentMiddleIndex());
226+
rightScrollCtrl = new FixedExtentScrollController(
227+
initialItem: widget.pickerModel.currentRightIndex());
214228
}
215229

216230
@override
@@ -222,7 +236,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
222236
builder: (BuildContext context, Widget child) {
223237
return new ClipRect(
224238
child: new CustomSingleChildLayout(
225-
delegate: new _BottomPickerLayout(widget.route.animation.value, theme,
239+
delegate: new _BottomPickerLayout(
240+
widget.route.animation.value, theme,
226241
showTitleActions: widget.route.showTitleActions),
227242
child: new GestureDetector(
228243
child: Material(
@@ -269,7 +284,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
269284
child: Container(
270285
padding: EdgeInsets.all(8.0),
271286
height: theme.containerHeight,
272-
decoration: BoxDecoration(color: theme.backgroundColor ?? Colors.white),
287+
decoration:
288+
BoxDecoration(color: theme.backgroundColor ?? Colors.white),
273289
child: NotificationListener(
274290
onNotification: (ScrollNotification notification) {
275291
if (notification.depth == 0 &&
@@ -350,8 +366,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
350366
style: theme.itemStyle,
351367
),
352368
_renderColumnView(
353-
ValueKey(
354-
widget.pickerModel.currentMiddleIndex() + widget.pickerModel.currentLeftIndex()),
369+
ValueKey(widget.pickerModel.currentMiddleIndex() +
370+
widget.pickerModel.currentLeftIndex()),
355371
theme,
356372
widget.pickerModel.rightStringAtIndex,
357373
rightScrollCtrl,
@@ -415,7 +431,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
415431
}
416432

417433
class _BottomPickerLayout extends SingleChildLayoutDelegate {
418-
_BottomPickerLayout(this.progress, this.theme, {this.itemCount, this.showTitleActions});
434+
_BottomPickerLayout(this.progress, this.theme,
435+
{this.itemCount, this.showTitleActions});
419436

420437
final double progress;
421438
final int itemCount;

lib/src/date_format.dart

+8-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ const String Z = 'Z';
223223
String formatDate(DateTime date, List<String> formats, LocaleType locale) {
224224
if (formats.first == ymdw) {
225225
final now = DateTime.now();
226-
if (date.year == now.year && date.month == now.month && date.day == now.day) {
226+
if (date.year == now.year &&
227+
date.month == now.month &&
228+
date.day == now.day) {
227229
//today
228230
return i18nObjInLocale(locale)['today'];
229231
} else if (date.year == now.year) {
@@ -284,7 +286,9 @@ String formatDate(DateTime date, List<String> formats, LocaleType locale) {
284286
} else if (format == h) {
285287
sb.write(date.hour % 12);
286288
} else if (format == am) {
287-
sb.write(date.hour < 12 ? i18nObjInLocale(locale)['am'] : i18nObjInLocale(locale)['pm']);
289+
sb.write(date.hour < 12
290+
? i18nObjInLocale(locale)['am']
291+
: i18nObjInLocale(locale)['pm']);
288292
} else if (format == nn) {
289293
sb.write(digits(date.minute, 2));
290294
} else if (format == n) {
@@ -329,4 +333,5 @@ String digits(int value, int length) {
329333
return '$value'.padLeft(length, "0");
330334
}
331335

332-
int dayInYear(DateTime date) => date.difference(new DateTime(date.year, 1, 1)).inDays;
336+
int dayInYear(DateTime date) =>
337+
date.difference(new DateTime(date.year, 1, 1)).inDays;

0 commit comments

Comments
 (0)