Liu Yanbo преди 6 години
родител
ревизия
290ed5aca3

+ 2 - 1
CHANGELOG.md

@@ -16,4 +16,5 @@
 ## [1.0.4] - add Dutch in readme
 ## [1.0.5] - add max/min time limit for Date Picker, add theme
 ## [1.0.6] - add comments
-## [1.0.7] - fix max/min time for datetime type picker
+## [1.0.7] - fix max/min time for datetime type picker
+## [1.0.8] - add Russian

+ 11 - 5
README.md

@@ -1,15 +1,21 @@
-# flutter_datetime_picker
+# Flutter Datetime Picker
 
 [![Pub](https://img.shields.io/pub/v/flutter_datetime_picker.svg?style=plastic)](https://pub.dartlang.org/packages/flutter_datetime_picker)
 
 A flutter date time picker inspired by [flutter-cupertino-date-picker](https://github.com/wuzhendev/flutter-cupertino-date-picker)
 
-you can choose date / time / date&time in English, Dutch and Chinese, and you can also custom your own picker content
+you can choose date / time / date&time in English, Dutch, Chinese and Russian
 
+and you can also custom your own picker content
 
-| Date picker | Time picker | Date & Time picker (Chinese) | Date & Time  picker (English-America)|Date & Time  picker (Dutch)|
-| ------- | ------- | ------- | ------- |------- |
-|![]( screen_date.png)|![]( screen_time.png)|![]( screen_datetime_chinese.png)|![]( screen_datetime_english.png)|![]( screen_datetime_dutch.png)|
+
+| Date picker | Time picker | Date & Time picker (Chinese) | 
+| ------- | ------- | ------- |
+| ![]( screen_date.png) | ![]( screen_time.png) | ![]( screen_datetime_chinese.png) |
+
+| Date & Time picker (Chinese) | Date & Time picker (America) | Date & Time picker (Dutch) | Date & Time picker (Russian) |
+| ------- | ------- | ------- | ------- |
+|![]( screen_datetime_chinese.png)|![]( screen_datetime_english.png)|![]( screen_datetime_dutch.png)|![]( screen_datetime_russian.png)|
 
 ## Usage
 ```

+ 0 - 4
example/ios/Runner.xcodeproj/project.pbxproj

@@ -8,7 +8,6 @@
 
 /* Begin PBXBuildFile section */
 		1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
-		2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
 		3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
 		3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
 		3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -40,7 +39,6 @@
 /* Begin PBXFileReference section */
 		1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
 		1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
-		2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
 		3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
 		3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
 		7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@@ -73,7 +71,6 @@
 		9740EEB11CF90186004384FC /* Flutter */ = {
 			isa = PBXGroup;
 			children = (
-				2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
 				3B80C3931E831B6300D905FE /* App.framework */,
 				3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
 				9740EEBA1CF902C7004384FC /* Flutter.framework */,
@@ -190,7 +187,6 @@
 				3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
 				9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
 				97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
-				2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
 				97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 33 - 8
example/lib/main.dart

@@ -35,8 +35,10 @@ class HomePage extends StatelessWidget {
                       maxTime: DateTime(2019, 6, 7),
                       theme: DatePickerTheme(
                           backgroundColor: Colors.blue,
-                          itemStyle: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
-                          doneStyle: TextStyle(color: Colors.white, fontSize: 16)),
+                          itemStyle: TextStyle(
+                              color: Colors.white, fontWeight: FontWeight.bold),
+                          doneStyle:
+                              TextStyle(color: Colors.white, fontSize: 16)),
                       onChanged: (date) {
                     print('change $date');
                   }, onConfirm: (date) {
@@ -49,7 +51,8 @@ class HomePage extends StatelessWidget {
                 )),
             FlatButton(
                 onPressed: () {
-                  DatePicker.showTimePicker(context, showTitleActions: true, onChanged: (date) {
+                  DatePicker.showTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
                     print('change $date');
                   }, onConfirm: (date) {
                     print('confirm $date');
@@ -61,11 +64,14 @@ class HomePage extends StatelessWidget {
                 )),
             FlatButton(
                 onPressed: () {
-                  DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
                     print('change $date');
                   }, onConfirm: (date) {
                     print('confirm $date');
-                  }, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.zh);
+                  },
+                      currentTime: DateTime(2008, 12, 31, 23, 12, 34),
+                      locale: LocaleType.zh);
                 },
                 child: Text(
                   'show date time picker (Chinese)',
@@ -73,7 +79,8 @@ class HomePage extends StatelessWidget {
                 )),
             FlatButton(
                 onPressed: () {
-                  DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
                     print('change $date');
                   }, onConfirm: (date) {
                     print('confirm $date');
@@ -85,16 +92,34 @@ class HomePage extends StatelessWidget {
                 )),
             FlatButton(
                 onPressed: () {
-                  DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
                     print('change $date');
                   }, onConfirm: (date) {
                     print('confirm $date');
-                  }, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.nl);
+                  },
+                      currentTime: DateTime(2008, 12, 31, 23, 12, 34),
+                      locale: LocaleType.nl);
                 },
                 child: Text(
                   'show date time picker (Dutch)',
                   style: TextStyle(color: Colors.blue),
                 )),
+            FlatButton(
+                onPressed: () {
+                  DatePicker.showDateTimePicker(context, showTitleActions: true,
+                      onChanged: (date) {
+                    print('change $date');
+                  }, onConfirm: (date) {
+                    print('confirm $date');
+                  },
+                      currentTime: DateTime(2008, 12, 31, 23, 12, 34),
+                      locale: LocaleType.ru);
+                },
+                child: Text(
+                  'show date time picker (Russian)',
+                  style: TextStyle(color: Colors.blue),
+                )),
           ],
         ),
       ),

+ 39 - 22
lib/flutter_datetime_picker.dart

@@ -36,9 +36,13 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: theme,
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
             pickerModel: DatePickerModel(
-                currentTime: currentTime, maxTime: maxTime, minTime: minTime, locale: locale)));
+                currentTime: currentTime,
+                maxTime: maxTime,
+                minTime: minTime,
+                locale: locale)));
   }
 
   ///
@@ -61,8 +65,10 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: theme,
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
-            pickerModel: TimePickerModel(currentTime: currentTime, locale: locale)));
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            pickerModel:
+                TimePickerModel(currentTime: currentTime, locale: locale)));
   }
 
   ///
@@ -85,8 +91,10 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: theme,
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
-            pickerModel: DateTimePickerModel(currentTime: currentTime, locale: locale)));
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            pickerModel:
+                DateTimePickerModel(currentTime: currentTime, locale: locale)));
   }
 
   ///
@@ -109,7 +117,8 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: theme,
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
             pickerModel: pickerModel));
   }
 }
@@ -152,13 +161,14 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
   @override
   AnimationController createAnimationController() {
     assert(_animationController == null);
-    _animationController = BottomSheet.createAnimationController(navigator.overlay);
+    _animationController =
+        BottomSheet.createAnimationController(navigator.overlay);
     return _animationController;
   }
 
   @override
-  Widget buildPage(
-      BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
+  Widget buildPage(BuildContext context, Animation<double> animation,
+      Animation<double> secondaryAnimation) {
     Widget bottomSheet = new MediaQuery.removePadding(
       context: context,
       removeTop: true,
@@ -179,7 +189,11 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
 
 class _DatePickerComponent extends StatefulWidget {
   _DatePickerComponent(
-      {Key key, @required this.route, this.onChanged, this.locale, this.pickerModel});
+      {Key key,
+      @required this.route,
+      this.onChanged,
+      this.locale,
+      this.pickerModel});
 
   final DateChangedCallback onChanged;
 
@@ -205,12 +219,12 @@ class _DatePickerState extends State<_DatePickerComponent> {
   }
 
   void refreshScrollOffset() {
-    leftScrollCtrl =
-        new FixedExtentScrollController(initialItem: widget.pickerModel.currentLeftIndex());
-    middleScrollCtrl =
-        new FixedExtentScrollController(initialItem: widget.pickerModel.currentMiddleIndex());
-    rightScrollCtrl =
-        new FixedExtentScrollController(initialItem: widget.pickerModel.currentRightIndex());
+    leftScrollCtrl = new FixedExtentScrollController(
+        initialItem: widget.pickerModel.currentLeftIndex());
+    middleScrollCtrl = new FixedExtentScrollController(
+        initialItem: widget.pickerModel.currentMiddleIndex());
+    rightScrollCtrl = new FixedExtentScrollController(
+        initialItem: widget.pickerModel.currentRightIndex());
   }
 
   @override
@@ -222,7 +236,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
         builder: (BuildContext context, Widget child) {
           return new ClipRect(
             child: new CustomSingleChildLayout(
-              delegate: new _BottomPickerLayout(widget.route.animation.value, theme,
+              delegate: new _BottomPickerLayout(
+                  widget.route.animation.value, theme,
                   showTitleActions: widget.route.showTitleActions),
               child: new GestureDetector(
                 child: Material(
@@ -269,7 +284,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
       child: Container(
           padding: EdgeInsets.all(8.0),
           height: theme.containerHeight,
-          decoration: BoxDecoration(color: theme.backgroundColor ?? Colors.white),
+          decoration:
+              BoxDecoration(color: theme.backgroundColor ?? Colors.white),
           child: NotificationListener(
               onNotification: (ScrollNotification notification) {
                 if (notification.depth == 0 &&
@@ -350,8 +366,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
             style: theme.itemStyle,
           ),
           _renderColumnView(
-              ValueKey(
-                  widget.pickerModel.currentMiddleIndex() + widget.pickerModel.currentLeftIndex()),
+              ValueKey(widget.pickerModel.currentMiddleIndex() +
+                  widget.pickerModel.currentLeftIndex()),
               theme,
               widget.pickerModel.rightStringAtIndex,
               rightScrollCtrl,
@@ -415,7 +431,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
 }
 
 class _BottomPickerLayout extends SingleChildLayoutDelegate {
-  _BottomPickerLayout(this.progress, this.theme, {this.itemCount, this.showTitleActions});
+  _BottomPickerLayout(this.progress, this.theme,
+      {this.itemCount, this.showTitleActions});
 
   final double progress;
   final int itemCount;

+ 8 - 3
lib/src/date_format.dart

@@ -223,7 +223,9 @@ const String Z = 'Z';
 String formatDate(DateTime date, List<String> formats, LocaleType locale) {
   if (formats.first == ymdw) {
     final now = DateTime.now();
-    if (date.year == now.year && date.month == now.month && date.day == now.day) {
+    if (date.year == now.year &&
+        date.month == now.month &&
+        date.day == now.day) {
       //today
       return i18nObjInLocale(locale)['today'];
     } else if (date.year == now.year) {
@@ -284,7 +286,9 @@ String formatDate(DateTime date, List<String> formats, LocaleType locale) {
     } else if (format == h) {
       sb.write(date.hour % 12);
     } else if (format == am) {
-      sb.write(date.hour < 12 ? i18nObjInLocale(locale)['am'] : i18nObjInLocale(locale)['pm']);
+      sb.write(date.hour < 12
+          ? i18nObjInLocale(locale)['am']
+          : i18nObjInLocale(locale)['pm']);
     } else if (format == nn) {
       sb.write(digits(date.minute, 2));
     } else if (format == n) {
@@ -329,4 +333,5 @@ String digits(int value, int length) {
   return '$value'.padLeft(length, "0");
 }
 
-int dayInYear(DateTime date) => date.difference(new DateTime(date.year, 1, 1)).inDays;
+int dayInYear(DateTime date) =>
+    date.difference(new DateTime(date.year, 1, 1)).inDays;

+ 21 - 9
lib/src/date_model.dart

@@ -44,7 +44,8 @@ class CommonPickerModel extends BasePickerModel {
 
   LocaleType locale;
 
-  CommonPickerModel({this.currentTime, locale}) : this.locale = locale ?? LocaleType.en;
+  CommonPickerModel({this.currentTime, locale})
+      : this.locale = locale ?? LocaleType.en;
 
   @override
   String leftStringAtIndex(int index) {
@@ -117,7 +118,11 @@ class DatePickerModel extends CommonPickerModel {
   DateTime maxTime;
   DateTime minTime;
 
-  DatePickerModel({DateTime currentTime, DateTime maxTime, DateTime minTime, LocaleType locale})
+  DatePickerModel(
+      {DateTime currentTime,
+      DateTime maxTime,
+      DateTime minTime,
+      LocaleType locale})
       : super(locale: locale) {
     this.maxTime = maxTime ?? DateTime(2049, 12, 31);
     this.minTime = minTime ?? DateTime(1970, 1, 1);
@@ -158,13 +163,17 @@ class DatePickerModel extends CommonPickerModel {
 
   int _maxDayOfCurrentMonth() {
     int dayCount = calcDateCount(currentTime.year, currentTime.month);
-    return currentTime.year == maxTime.year && currentTime.month == maxTime.month
+    return currentTime.year == maxTime.year &&
+            currentTime.month == maxTime.month
         ? maxTime.day
         : dayCount;
   }
 
   int _minDayOfCurrentMonth() {
-    return currentTime.year == minTime.year && currentTime.month == minTime.month ? minTime.day : 1;
+    return currentTime.year == minTime.year &&
+            currentTime.month == minTime.month
+        ? minTime.day
+        : 1;
   }
 
   void _fillMiddleLists() {
@@ -319,7 +328,8 @@ class DatePickerModel extends CommonPickerModel {
 
 //a time picker model
 class TimePickerModel extends CommonPickerModel {
-  TimePickerModel({DateTime currentTime, LocaleType locale}) : super(locale: locale) {
+  TimePickerModel({DateTime currentTime, LocaleType locale})
+      : super(locale: locale) {
     this.currentTime = currentTime ?? DateTime.now();
 
     _currentLeftIndex = this.currentTime.hour;
@@ -366,14 +376,15 @@ class TimePickerModel extends CommonPickerModel {
 
   @override
   DateTime finalTime() {
-    return DateTime(currentTime.year, currentTime.month, currentTime.day, _currentLeftIndex,
-        _currentMiddleIndex, _currentRightIndex);
+    return DateTime(currentTime.year, currentTime.month, currentTime.day,
+        _currentLeftIndex, _currentMiddleIndex, _currentRightIndex);
   }
 }
 
 //a date&time picker model
 class DateTimePickerModel extends CommonPickerModel {
-  DateTimePickerModel({DateTime currentTime, LocaleType locale}) : super(locale: locale) {
+  DateTimePickerModel({DateTime currentTime, LocaleType locale})
+      : super(locale: locale) {
     this.currentTime = currentTime ?? DateTime.now();
     _currentLeftIndex = 0;
     _currentMiddleIndex = this.currentTime.hour;
@@ -407,7 +418,8 @@ class DateTimePickerModel extends CommonPickerModel {
   @override
   DateTime finalTime() {
     DateTime time = currentTime.add(Duration(days: _currentLeftIndex));
-    return DateTime(time.year, time.month, time.day, _currentMiddleIndex, _currentRightIndex);
+    return DateTime(time.year, time.month, time.day, _currentMiddleIndex,
+        _currentRightIndex);
   }
 
   @override

+ 28 - 2
lib/src/i18n_model.dart

@@ -47,8 +47,34 @@ final _i18nModel = {
     'cancel': '取消',
     'done': '确定',
     'today': '今天',
-    'monthShort': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
-    'monthLong': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
+    'monthShort': [
+      '一月',
+      '二月',
+      '三月',
+      '四月',
+      '五月',
+      '六月',
+      '七月',
+      '八月',
+      '九月',
+      '十月',
+      '十一月',
+      '十二月'
+    ],
+    'monthLong': [
+      '一月',
+      '二月',
+      '三月',
+      '四月',
+      '五月',
+      '六月',
+      '七月',
+      '八月',
+      '九月',
+      '十月',
+      '十一月',
+      '十二月'
+    ],
     'day': ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'],
     'am': '上午',
     'pm': '下午'

+ 1 - 1
pubspec.yaml

@@ -1,6 +1,6 @@
 name: flutter_datetime_picker
 description: A date time picker for flutter, you can choose date / time / date&time in English Dutch and Chinese, and you can also custom your own picker content
-version: 1.0.7
+version: 1.0.8
 author: Realank <realank@126.com>
 homepage: https://github.com/Realank/flutter_datetime_picker
 

BIN
screen_datetime_dutch.png


BIN
screen_datetime_russian.png