Liu Yanbo il y a 6 ans
Parent
commit
fa4be584ee
3 fichiers modifiés avec 24 ajouts et 155 suppressions
  1. 3 8
      lib/src/date_format.dart
  2. 12 25
      lib/src/date_model.dart
  3. 9 122
      lib/src/i18n_model.dart

+ 3 - 8
lib/src/date_format.dart

@@ -223,9 +223,7 @@ 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) {
@@ -297,9 +295,7 @@ 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) {
@@ -344,5 +340,4 @@ 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;

+ 12 - 25
lib/src/date_model.dart

@@ -44,8 +44,7 @@ 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) {
@@ -118,11 +117,7 @@ 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);
@@ -164,17 +159,13 @@ 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() {
@@ -361,8 +352,7 @@ 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;
@@ -410,17 +400,16 @@ class TimePickerModel extends CommonPickerModel {
   @override
   DateTime finalTime() {
     return currentTime.isUtc
-        ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day,
-            _currentLeftIndex, _currentMiddleIndex, _currentRightIndex)
-        : DateTime(currentTime.year, currentTime.month, currentTime.day,
-            _currentLeftIndex, _currentMiddleIndex, _currentRightIndex);
+        ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day, _currentLeftIndex,
+            _currentMiddleIndex, _currentRightIndex)
+        : 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;
@@ -455,10 +444,8 @@ class DateTimePickerModel extends CommonPickerModel {
   DateTime finalTime() {
     DateTime time = currentTime.add(Duration(days: _currentLeftIndex));
     return currentTime.isUtc
-        ? DateTime.utc(time.year, time.month, time.day, _currentMiddleIndex,
-            _currentRightIndex)
-        : DateTime(time.year, time.month, time.day, _currentMiddleIndex,
-            _currentRightIndex);
+        ? DateTime.utc(time.year, time.month, time.day, _currentMiddleIndex, _currentRightIndex)
+        : DateTime(time.year, time.month, time.day, _currentMiddleIndex, _currentRightIndex);
   }
 
   @override

+ 9 - 122
lib/src/i18n_model.dart

@@ -1,23 +1,4 @@
-enum LocaleType {
-  en,
-  fa,
-  zh,
-  nl,
-  ru,
-  it,
-  fr,
-  es,
-  pl,
-  pt,
-  ko,
-  ar,
-  tr,
-  jp,
-  de,
-  da,
-  mn,
-  bn
-}
+enum LocaleType { en, fa, zh, nl, ru, it, fr, es, pl, pt, ko, ar, tr, jp, de, da, mn, bn }
 
 final _i18nModel = {
   'en': {
@@ -124,15 +105,7 @@ final _i18nModel = {
       'بهمن',
       'اسفند'
     ],
-    'day': [
-      'دوشنبه',
-      'سه شنبه',
-      'چهارشنبه',
-      'پنج شنبه',
-      'جمعه',
-      'شنبه',
-      'یکشنبه'
-    ],
+    'day': ['دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنج شنبه', 'جمعه', 'شنبه', 'یکشنبه'],
     'am': 'صبح',
     'pm': 'عصر'
   },
@@ -141,34 +114,8 @@ final _i18nModel = {
     'cancel': '取消',
     'done': '确定',
     'today': '今天',
-    'monthShort': [
-      '一月',
-      '二月',
-      '三月',
-      '四月',
-      '五月',
-      '六月',
-      '七月',
-      '八月',
-      '九月',
-      '十月',
-      '十一月',
-      '十二月'
-    ],
-    'monthLong': [
-      '一月',
-      '二月',
-      '三月',
-      '四月',
-      '五月',
-      '六月',
-      '七月',
-      '八月',
-      '九月',
-      '十月',
-      '十一月',
-      '十二月'
-    ],
+    'monthShort': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
+    'monthLong': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
     'day': ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'],
     'am': '上午',
     'pm': '下午'
@@ -438,34 +385,8 @@ final _i18nModel = {
     'cancel': '취소',
     'done': '완료',
     'today': '오늘',
-    'monthShort': [
-      '1월',
-      '2월',
-      '3월',
-      '4월',
-      '5월',
-      '6월',
-      '7월',
-      '8월',
-      '9월',
-      '10월',
-      '11월',
-      '12월'
-    ],
-    'monthLong': [
-      '1월',
-      '2월',
-      '3월',
-      '4월',
-      '5월',
-      '6월',
-      '7월',
-      '8월',
-      '9월',
-      '10월',
-      '11월',
-      '12월'
-    ],
+    'monthShort': ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
+    'monthLong': ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
     'day': ['월', '화', '수', '목', '금', '토', '일'],
     'am': '오전',
     'pm': '오후'
@@ -502,15 +423,7 @@ final _i18nModel = {
       'نوفمبر',
       'ديسمبر'
     ],
-    'day': [
-      'الإثنين',
-      'الثلاثاء',
-      'الأربعاء',
-      'الخميس',
-      'الجمعه',
-      'السبت',
-      'الاحد'
-    ],
+    'day': ['الإثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعه', 'السبت', 'الاحد'],
     'am': 'ص',
     'pm': 'م'
   },
@@ -555,34 +468,8 @@ final _i18nModel = {
     'cancel': 'キャンセル',
     'done': '決定する',
     'today': '今日',
-    'monthShort': [
-      '一月',
-      '二月',
-      '三月',
-      '四月',
-      '五月',
-      '六月',
-      '七月',
-      '八月',
-      '九月',
-      '十月',
-      '十一月',
-      '十二月'
-    ],
-    'monthLong': [
-      '一月',
-      '二月',
-      '三月',
-      '四月',
-      '五月',
-      '六月',
-      '七月',
-      '八月',
-      '九月',
-      '十月',
-      '十一月',
-      '十二月'
-    ],
+    'monthShort': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
+    'monthLong': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
     'day': ['月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日', '日曜日'],
     'am': '朝',
     'pm': '午後'