Skip to content

Commit

Permalink
Merge branch 'master' into feature/customizable_title_actions
Browse files Browse the repository at this point in the history
  • Loading branch information
junqi committed Jun 25, 2020
2 parents 561f98f + 7d6b157 commit a2a7701
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@
## [1.3.1] - add header color
## [1.3.2] - add more languages
## [1.3.4] - add more languages
## [1.3.5] - add 12 hour time picker with AM/PM
## [1.3.5] - add 12 hour time picker with AM/PM
## [1.3.6] - fix error with Diagnosticable in newer Flutter versions
## [1.3.7] - fix some issues
## [1.3.8] - add Swedish language and fix issues
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A flutter date time picker inspired by [flutter-cupertino-date-picker](https://g

you can choose date / time / date&time in multiple languages:

- Albanian(sq)
- Arabic(ar)
- Armenian(hy)
- Azerbaijan(az)
Expand All @@ -29,6 +30,7 @@ you can choose date / time / date&time in multiple languages:
- Portuguese(pt)
- Russian(ru)
- Spanish(es)
- Swedish(sv)
- Thai(th)
- Turkish(tr)
- Vietnamese(vi)
Expand Down
20 changes: 19 additions & 1 deletion lib/flutter_datetime_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export 'package:flutter_datetime_picker/src/date_model.dart';
export 'package:flutter_datetime_picker/src/i18n_model.dart';

typedef DateChangedCallback(DateTime time);
typedef DateCancelledCallback();
typedef String StringAtIndexCallBack(int index);

class DatePicker {
Expand All @@ -25,6 +26,7 @@ class DatePicker {
DateTime maxTime,
DateChangedCallback onChanged,
DateChangedCallback onConfirm,
DateCancelledCallback onCancel,
locale: LocaleType.en,
DateTime currentTime,
DatePickerTheme theme,
Expand All @@ -35,6 +37,7 @@ class DatePicker {
showTitleActions: showTitleActions,
onChanged: onChanged,
onConfirm: onConfirm,
onCancel: onCancel,
locale: locale,
theme: theme,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
Expand All @@ -51,6 +54,7 @@ class DatePicker {
bool showSecondsColumn: true,
DateChangedCallback onChanged,
DateChangedCallback onConfirm,
DateCancelledCallback onCancel,
locale: LocaleType.en,
DateTime currentTime,
DatePickerTheme theme,
Expand All @@ -61,6 +65,7 @@ class DatePicker {
showTitleActions: showTitleActions,
onChanged: onChanged,
onConfirm: onConfirm,
onCancel: onCancel,
locale: locale,
theme: theme,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
Expand All @@ -76,6 +81,7 @@ class DatePicker {
bool showTitleActions: true,
DateChangedCallback onChanged,
DateChangedCallback onConfirm,
DateCancelledCallback onCancel,
locale: LocaleType.en,
DateTime currentTime,
DatePickerTheme theme,
Expand All @@ -86,6 +92,7 @@ class DatePicker {
showTitleActions: showTitleActions,
onChanged: onChanged,
onConfirm: onConfirm,
onCancel: onCancel,
locale: locale,
theme: theme,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
Expand All @@ -103,6 +110,7 @@ class DatePicker {
DateTime maxTime,
DateChangedCallback onChanged,
DateChangedCallback onConfirm,
DateCancelledCallback onCancel,
locale: LocaleType.en,
DateTime currentTime,
DatePickerTheme theme,
Expand All @@ -114,6 +122,7 @@ class DatePicker {
renderCustomTitleActionsView: renderCustomTitleActionsView,
onChanged: onChanged,
onConfirm: onConfirm,
onCancel: onCancel,
locale: locale,
theme: theme,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
Expand All @@ -129,6 +138,7 @@ class DatePicker {
bool showTitleActions: true,
DateChangedCallback onChanged,
DateChangedCallback onConfirm,
DateCancelledCallback onCancel,
locale: LocaleType.en,
BasePickerModel pickerModel,
DatePickerTheme theme,
Expand All @@ -139,6 +149,7 @@ class DatePicker {
showTitleActions: showTitleActions,
onChanged: onChanged,
onConfirm: onConfirm,
onCancel: onCancel,
locale: locale,
theme: theme,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
Expand All @@ -152,6 +163,7 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
this.renderCustomTitleActionsView,
this.onChanged,
this.onConfirm,
this.onCancel,
theme,
this.barrierLabel,
this.locale,
Expand All @@ -165,6 +177,7 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
final Function renderCustomTitleActionsView;
final DateChangedCallback onChanged;
final DateChangedCallback onConfirm;
final DateCancelledCallback onCancel;
final DatePickerTheme theme;
final LocaleType locale;
final BasePickerModel pickerModel;
Expand Down Expand Up @@ -437,7 +450,12 @@ class _DatePickerState extends State<_DatePickerComponent> {
'$cancel',
style: theme.cancelStyle,
),
onPressed: () => Navigator.pop(context),
onPressed: () {
Navigator.pop(context);
if (widget.route.onCancel != null) {
widget.route.onCancel();
}
},
),
),
Container(
Expand Down
4 changes: 4 additions & 0 deletions lib/src/date_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ String formatDate(DateTime date, List<String> formats, LocaleType locale) {
return formatDate(date, [D, ', ', dd, ' ', M], locale);
} else if (locale == LocaleType.jp) {
return formatDate(date, [mm, '月', dd, '日', D], locale);
} else if (locale == LocaleType.si) {
return formatDate(date, [D, ', ', dd, '. ', M, '.'], locale);
} else {
return formatDate(date, [D, ' ', M, ' ', dd], locale);
}
Expand All @@ -257,6 +259,8 @@ String formatDate(DateTime date, List<String> formats, LocaleType locale) {
return formatDate(date, [D, ', ', dd, ' ', M, ' ', yyyy], locale);
} else if (locale == LocaleType.jp) {
return formatDate(date, [yyyy, '年', mm, '月', dd, '日', D], locale);
} else if (locale == LocaleType.si) {
return formatDate(date, [D, ', ', dd, '. ', M, '. ', yyyy], locale);
} else {
return formatDate(date, [D, ' ', M, ' ', dd, ', ', yyyy], locale);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/datetime_picker_theme.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class DatePickerTheme with DiagnosticableMixin {
// Migrate DiagnosticableMixin to Diagnosticable until
// https://github.com/flutter/flutter/pull/51495 makes it into stable (v1.15.21)
class DatePickerTheme with Diagnosticable {
final TextStyle cancelStyle;
final TextStyle doneStyle;
final TextStyle itemStyle;
Expand Down
171 changes: 164 additions & 7 deletions lib/src/i18n_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ enum LocaleType {
bg,
eu,
cat,
th
th,
si,
no,
sq,
sv
}

final _i18nModel = {
Expand Down Expand Up @@ -106,6 +110,9 @@ final _i18nModel = {
'done': 'تایید',
'today': 'امروز',
'monthShort': [
'دی',
'بهمن',
'اسفند',
'فروردین',
'اردیبهشت',
'خرداد',
Expand All @@ -115,11 +122,11 @@ final _i18nModel = {
'مهر',
'آبان',
'آذر',
'دی',
'بهمن',
'اسفند'
],
'monthLong': [
'دی',
'بهمن',
'اسفند',
'فروردین',
'اردیبهشت',
'خرداد',
Expand All @@ -129,9 +136,6 @@ final _i18nModel = {
'مهر',
'آبان',
'آذر',
'دی',
'بهمن',
'اسفند'
],
'day': ['دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنج شنبه', 'جمعه', 'شنبه', 'یکشنبه'],
'am': 'صبح',
Expand Down Expand Up @@ -949,6 +953,151 @@ final _i18nModel = {
'am': 'AM',
'pm': 'PM'
},
'si': {
//Slovenian
'cancel': 'Prekliči',
'done': 'V redu',
'today': 'Danes',
'monthShort': [
'jan',
'feb',
'mar',
'apr',
'maj',
'jun',
'jul',
'avg',
'sep',
'okt',
'nov',
'dec'
],
'monthLong': [
'januar',
'februar',
'marec',
'april',
'maj',
'junij',
'julij',
'avgust',
'september',
'oktober',
'november',
'december'
],
'day': ['pon', 'tor', 'sre', 'čet', 'pet', 'sob', 'ned'],
'am': '',
'pm': ''
},
'no': {
'cancel': 'Avbryt',
'done': 'Ferdig',
'today': 'Idag',
'monthShort': [
'Jan',
'Feb',
'Mar',
'Apr',
'Mai',
'Jun',
'Jul',
'Aug',
'Sep',
'Okt',
'Nov',
'Des'
],
'monthLong': [
'Januar',
'Februar',
'Mars',
'April',
'Mai',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'Desember'
],
'day': ['Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør', 'Søn'],
'am': '',
'pm': ''
},
'sq': {
'cancel': 'Anulo',
'done': 'Perfundo',
'today': 'Sot',
'monthShort': [
'Jan',
'Shk',
'Mar',
'Pri',
'Maj',
'Qer',
'Kor',
'Gus',
'Sht',
'Tet',
'Nen',
'Dhj'
],
'monthLong': [
'Janar',
'Shkurt',
'Mars',
'Prill',
'Maj',
'Qershor',
'Korrik',
'Gusht',
'Shtator',
'Tetor',
'Nentor',
'Dhjetor'
],
'day': ['Hen', 'Mar', 'Mer', 'Enj', 'Pre', 'Sht', 'Die'],
'am': 'PD',
'pm': 'MD'
},
'sv': {
'cancel': 'Avbryt',
'done': 'Klar',
'today': 'I dag',
'monthShort': [
'Jan',
'Feb',
'Mar',
'Apr',
'Maj',
'Jun',
'Jul',
'Aug',
'Sep',
'Okt',
'Nov',
'Dec'
],
'monthLong': [
'Januari',
'Februari',
'Mars',
'April',
'Maj',
'Juni',
'Juli',
'Augusti',
'September',
'Oktober',
'November',
'December'
],
'day': ['Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör', 'Sön'],
'am': 'AM',
'pm': 'PM'
}
};
//get international object
Map<String, dynamic> i18nObjInLocale(LocaleType type) {
Expand Down Expand Up @@ -1005,6 +1154,14 @@ Map<String, dynamic> i18nObjInLocale(LocaleType type) {
return _i18nModel['cat'];
case LocaleType.th:
return _i18nModel['th'];
case LocaleType.si:
return _i18nModel['si'];
case LocaleType.no:
return _i18nModel['no'];
case LocaleType.sq:
return _i18nModel['sq'];
case LocaleType.sv:
return _i18nModel['sv'];
default:
return _i18nModel['en'];
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.3.5
version: 1.3.8
homepage: https://github.com/Realank/flutter_datetime_picker

environment:
Expand Down

0 comments on commit a2a7701

Please sign in to comment.