Pārlūkot izejas kodu

Merge pull request #2 from daanvandenhoek/master

Added Dutch Support
刘彦博 7 gadi atpakaļ
vecāks
revīzija
7906a15396
3 mainītis faili ar 147 papildinājumiem un 47 dzēšanām
  1. 57 30
      lib/flutter_datetime_picker.dart
  2. 26 17
      lib/src/dateModel.dart
  3. 64 0
      lib/src/date_format.dart

+ 57 - 30
lib/flutter_datetime_picker.dart

@@ -1,10 +1,11 @@
 library flutter_datetime_picker;
 
-export 'package:flutter_datetime_picker/src/dateModel.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_datetime_picker/src/dateModel.dart';
 
+export 'package:flutter_datetime_picker/src/dateModel.dart';
+
 typedef DateChangedCallback(DateTime time);
 typedef String StringAtIndexCallBack(int index);
 
@@ -31,8 +32,10 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: Theme.of(context, shadowThemeOnly: true),
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
-            pickerModel: DatePickerModel(currentTime: currentTime, locale: locale)));
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            pickerModel:
+                DatePickerModel(currentTime: currentTime, locale: locale)));
   }
 
   ///
@@ -52,8 +55,10 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: Theme.of(context, shadowThemeOnly: true),
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
-            pickerModel: TimePickerModel(currentTime: currentTime, locale: locale)));
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            pickerModel:
+                TimePickerModel(currentTime: currentTime, locale: locale)));
   }
 
   ///
@@ -73,8 +78,10 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: Theme.of(context, shadowThemeOnly: true),
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
-            pickerModel: DateTimePickerModel(currentTime: currentTime, locale: locale)));
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            pickerModel:
+                DateTimePickerModel(currentTime: currentTime, locale: locale)));
   }
 
   ///
@@ -94,7 +101,8 @@ class DatePicker {
             onConfirm: onConfirm,
             locale: locale,
             theme: Theme.of(context, shadowThemeOnly: true),
-            barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
+            barrierLabel:
+                MaterialLocalizations.of(context).modalBarrierDismissLabel,
             pickerModel: pickerModel));
   }
 }
@@ -136,13 +144,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,
@@ -162,7 +171,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;
 
@@ -188,12 +201,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
@@ -281,7 +294,9 @@ class _DatePickerState extends State<_DatePickerComponent> {
                       alignment: Alignment.center,
                       child: Text(
                         content,
-                        style: TextStyle(color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
+                        style: TextStyle(
+                            color: Color(0xFF000046),
+                            fontSize: _kDatePickerFontSize),
                         textAlign: TextAlign.start,
                       ),
                     );
@@ -295,16 +310,21 @@ class _DatePickerState extends State<_DatePickerComponent> {
       child: Row(
         mainAxisAlignment: MainAxisAlignment.spaceBetween,
         children: <Widget>[
-          _renderColumnView(widget.pickerModel.leftStringAtIndex, leftScrollCtrl,
+          _renderColumnView(
+              widget.pickerModel.leftStringAtIndex,
+              leftScrollCtrl,
               widget.pickerModel.layoutProportions()[0], (index) {
             widget.pickerModel.setLeftIndex(index);
             _notifyDateChanged();
           }, null),
           Text(
             widget.pickerModel.leftDivider(),
-            style: TextStyle(color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
+            style: TextStyle(
+                color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
           ),
-          _renderColumnView(widget.pickerModel.middleStringAtIndex, middleScrollCtrl,
+          _renderColumnView(
+              widget.pickerModel.middleStringAtIndex,
+              middleScrollCtrl,
               widget.pickerModel.layoutProportions()[1], (index) {
             widget.pickerModel.setMiddleIndex(index);
           }, (index) {
@@ -314,9 +334,12 @@ class _DatePickerState extends State<_DatePickerComponent> {
           }),
           Text(
             widget.pickerModel.rightDivider(),
-            style: TextStyle(color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
+            style: TextStyle(
+                color: Color(0xFF000046), fontSize: _kDatePickerFontSize),
           ),
-          _renderColumnView(widget.pickerModel.rightStringAtIndex, rightScrollCtrl,
+          _renderColumnView(
+              widget.pickerModel.rightStringAtIndex,
+              rightScrollCtrl,
               widget.pickerModel.layoutProportions()[2], (index) {
             widget.pickerModel.setRightIndex(index);
             _notifyDateChanged();
@@ -374,18 +397,22 @@ class _DatePickerState extends State<_DatePickerComponent> {
   }
 
   String _localeDone() {
-    if (widget.locale.matchAsPrefix('cn') == null) {
-      return 'Done';
-    } else {
+    if (widget.locale.matchAsPrefix('cn') != null) {
       return '确定';
+    } else if (widget.locale.matchAsPrefix('nl') != null) {
+      return 'Klaar';
+    } else {
+      return 'Done';
     }
   }
 
   String _localeCancel() {
-    if (widget.locale.matchAsPrefix('cn') == null) {
-      return 'Cancel';
-    } else {
+    if (widget.locale.matchAsPrefix('cn') != null) {
       return '取消';
+    } else if (widget.locale.matchAsPrefix('nl') != null) {
+      return 'Annuleer';
+    } else {
+      return 'Cancel';
     }
   }
 }

+ 26 - 17
lib/src/dateModel.dart

@@ -111,7 +111,11 @@ class DatePickerModel extends CommonPickerModel {
     return 30;
   }
 
-  DatePickerModel({this.maxYear = 2050, this.minYear = 1970, DateTime currentTime, String locale})
+  DatePickerModel(
+      {this.maxYear = 2050,
+      this.minYear = 1970,
+      DateTime currentTime,
+      String locale})
       : super(locale: locale) {
     if (currentTime != null) {
       int year = currentTime.year;
@@ -145,7 +149,8 @@ class DatePickerModel extends CommonPickerModel {
 
   void fillRightLists() {
     this.rightList = List.generate(
-        _calcDateCount(_currentLeftIndex + minYear, _currentMiddleIndex + 1), (int index) {
+        _calcDateCount(_currentLeftIndex + minYear, _currentMiddleIndex + 1),
+        (int index) {
       return '${index + 1}${_localeDay()}';
     });
   }
@@ -160,7 +165,8 @@ class DatePickerModel extends CommonPickerModel {
   void setMiddleIndex(int index) {
     _currentMiddleIndex = index;
     fillRightLists();
-    final dayCount = _calcDateCount(_currentLeftIndex + minYear, _currentMiddleIndex + 1);
+    final dayCount =
+        _calcDateCount(_currentLeftIndex + minYear, _currentMiddleIndex + 1);
     if (_currentRightIndex >= dayCount) {
       _currentRightIndex = dayCount;
     }
@@ -199,26 +205,26 @@ class DatePickerModel extends CommonPickerModel {
   }
 
   String _localeYear() {
-    if (locale.matchAsPrefix('zh') == null) {
-      return '';
-    } else {
+    if (locale.matchAsPrefix('zh') != null) {
       return '年';
+    } else {
+      return '';
     }
   }
 
   String _localeMonth() {
-    if (locale.matchAsPrefix('zh') == null) {
-      return '';
-    } else {
+    if (locale.matchAsPrefix('zh') != null) {
       return '月';
+    } else {
+      return '';
     }
   }
 
   String _localeDay() {
-    if (locale.matchAsPrefix('zh') == null) {
-      return '';
-    } else {
+    if (locale.matchAsPrefix('zh') != null) {
       return '日';
+    } else {
+      return '';
     }
   }
 
@@ -232,7 +238,8 @@ class DatePickerModel extends CommonPickerModel {
 }
 
 class TimePickerModel extends CommonPickerModel {
-  TimePickerModel({DateTime currentTime, String locale}) : super(locale: locale) {
+  TimePickerModel({DateTime currentTime, String locale})
+      : super(locale: locale) {
     this.currentTime = currentTime ?? DateTime.now();
     _currentLeftIndex = this.currentTime.hour;
     _currentMiddleIndex = this.currentTime.minute;
@@ -278,13 +285,14 @@ 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);
   }
 }
 
 class DateTimePickerModel extends CommonPickerModel {
-  DateTimePickerModel({DateTime currentTime, String locale}) : super(locale: locale) {
+  DateTimePickerModel({DateTime currentTime, String locale})
+      : super(locale: locale) {
     this.currentTime = currentTime ?? DateTime.now();
     _currentLeftIndex = 0;
     _currentMiddleIndex = this.currentTime.hour;
@@ -318,7 +326,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

+ 64 - 0
lib/src/date_format.dart

@@ -234,18 +234,24 @@ String formatDate(DateTime date, List<String> formats, String locale) {
       //today
       if (locale == 'zh') {
         return '今天';
+      } else if (locale == 'nl') {
+        return 'Vandaag';
       } else {
         return 'Today';
       }
     } else if (date.year == now.year) {
       if (locale == 'zh') {
         return formatDate(date, [mm, '月', dd, '日 ', D], locale);
+      } else if (locale == 'nl') {
+        return formatDate(date, [D, ' ', dd, ' ', M], locale);
       } else {
         return formatDate(date, [D, ' ', M, ' ', dd], locale);
       }
     } else {
       if (locale == 'zh') {
         return formatDate(date, [yyyy, '年', mm, '月', dd, '日 ', D], locale);
+      } else if (locale == 'nl') {
+        return formatDate(date, [D, ' ', dd, ' ', M, ' ', yyyy], locale);
       } else {
         return formatDate(date, [D, ' ', M, ' ', dd, ',', yyyy], locale);
       }
@@ -266,12 +272,16 @@ String formatDate(DateTime date, List<String> formats, String locale) {
     } else if (format == MM) {
       if (locale == 'zh') {
         sb.write(monthZH[date.month - 1]);
+      } else if (locale == 'nl') {
+        sb.write(monthLongNL[date.month - 1]);
       } else {
         sb.write(monthLong[date.month - 1]);
       }
     } else if (format == M) {
       if (locale == 'zh') {
         sb.write(monthZH[date.month - 1]);
+      } else if (locale == 'nl') {
+        sb.write(monthShortNL[date.month - 1]);
       } else {
         sb.write(monthShort[date.month - 1]);
       }
@@ -288,12 +298,16 @@ String formatDate(DateTime date, List<String> formats, String locale) {
     } else if (format == DD) {
       if (locale == 'zh') {
         sb.write(dayZH[date.weekday - 1]);
+      } else if (locale == 'nl') {
+        sb.write(dayLongNL[date.weekday - 1]);
       } else {
         sb.write(dayLong[date.weekday - 1]);
       }
     } else if (format == D) {
       if (locale == 'zh') {
         sb.write(dayZH[date.weekday - 1]);
+      } else if (locale == 'nl') {
+        sb.write(dayShortNL[date.weekday - 1]);
       } else {
         sb.write(dayShort[date.weekday - 1]);
       }
@@ -434,5 +448,55 @@ const List<String> dayLong = const [
   'Sunday'
 ];
 
+const List<String> monthLongNL = const <String>[
+  'Januari',
+  'Februari',
+  'Maart',
+  'April',
+  'Mei',
+  'Juni',
+  'Juli',
+  'Augustus',
+  'September',
+  'Oktober',
+  'November',
+  'December',
+];
+
+const List<String> monthShortNL = const <String>[
+  'Jan',
+  'Feb',
+  'Mar',
+  'Apr',
+  'Mei',
+  'Jun',
+  'Jul',
+  'Aug',
+  'Sep',
+  'Okt',
+  'Nov',
+  'Dec',
+];
+
+const List<String> dayLongNL = const <String>[
+  'Maandag',
+  'Dinsdag',
+  'Woensdag',
+  'Donderdag',
+  'Vrijdag',
+  'Zaterdag',
+  'Zondag',
+];
+
+const List<String> dayShortNL = const <String>[
+  'Ma',
+  'Di',
+  'Wo',
+  'Do',
+  'Vr',
+  'Za',
+  'Zo',
+];
+
 int dayInYear(DateTime date) =>
     date.difference(new DateTime(date.year, 1, 1)).inDays;