Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AM/PM Merged, Updated, Fixed #54

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

/* 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, ); }; };
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
Expand All @@ -30,8 +25,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -41,15 +34,12 @@
/* 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>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand All @@ -63,8 +53,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -74,10 +62,7 @@
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
9740EEB21CF90195004384FC /* Debug.xcconfig */,
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
9740EEB31CF90195004384FC /* Generated.xcconfig */,
Expand Down Expand Up @@ -192,7 +177,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;
Expand All @@ -212,7 +196,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -265,7 +249,6 @@
/* Begin XCBuildConfiguration section */
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -319,7 +302,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down
9 changes: 4 additions & 5 deletions example/lib/date_picker_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class _DatePickerBottomSheetState extends State<DatePickerBottomSheet> {
@override
Widget build(BuildContext context) {
// create locale radio list
List<Widget> radios = List<Widget>();
_locales.forEach((locale) {
radios.add(Container(
List<Widget> radios = _locales.map((locale) {
return Container(
margin: EdgeInsets.only(right: 8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
Expand All @@ -55,8 +54,8 @@ class _DatePickerBottomSheetState extends State<DatePickerBottomSheet> {
.substring(locale.toString().indexOf('.') + 1)),
],
),
));
});
);
}).toList();

TextStyle hintTextStyle =
Theme.of(context).textTheme.subhead.apply(color: Color(0xFF999999));
Expand Down
9 changes: 4 additions & 5 deletions example/lib/datetime_picker_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ class _DateTimePickerBottomSheetState extends State<DateTimePickerBottomSheet> {

@override
Widget build(BuildContext context) {
List<Widget> radios = List<Widget>();
_locales.forEach((locale) {
radios.add(Container(
List<Widget> radios = _locales.map((locale) {
return Container(
margin: EdgeInsets.only(right: 8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
Expand All @@ -82,8 +81,8 @@ class _DateTimePickerBottomSheetState extends State<DateTimePickerBottomSheet> {
.substring(locale.toString().indexOf('.') + 1)),
],
),
));
});
);
}).toList();

TextStyle hintTextStyle =
Theme.of(context).textTheme.subhead.apply(color: Color(0xFF999999));
Expand Down
2 changes: 1 addition & 1 deletion example/lib/time_picker_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const String MAX_DATETIME = '2021-11-25 22:45:10';
const String INIT_DATETIME = '2019-05-17 18:13:15';

class _TimePickerBottomSheetState extends State<TimePickerBottomSheet> {
String _format = 'HH:mm';
String _format = 'hh:mm a';
TextEditingController _formatCtrl = TextEditingController();

DateTime _dateTime;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/date_picker_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const double DATETIME_PICKER_ITEM_HEIGHT = 36.0;
const TextStyle DATETIME_PICKER_ITEM_TEXT_STYLE =
const TextStyle(color: Color(0xFF000046), fontSize: 16.0);

class DateTimePickerTheme with DiagnosticableMixin {
class DateTimePickerTheme with Diagnosticable {
final cancelDefault = const Text('OK');

/// DateTimePicker theme.
Expand Down
35 changes: 29 additions & 6 deletions lib/src/date_time_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class DateTimeFormatter {
return format.contains(RegExp(r'[yMdE]'));
}

/// Check if the date format is for time(contain H、m、s) or not.
/// Check if the date format is for time(contain H、h、m、s、a) or not.
static bool isTimeFormat(String format) {
return format.contains(RegExp(r'[Hms]'));
return format.contains(RegExp(r'[Hhmsa]'));
}

/// Split date format to array.
Expand Down Expand Up @@ -93,8 +93,12 @@ class DateTimeFormatter {
result = _formatWeek(value, result, locale);
}
// format hour text
if (format.contains('h')) {
result = _format12Hour(value, result, locale);
}
// format hour text
if (format.contains('H')) {
result = _formatHour(value, result, locale);
result = _format24Hour(value, result, locale);
}
// format minute text
if (format.contains('m')) {
Expand All @@ -104,6 +108,10 @@ class DateTimeFormatter {
if (format.contains('s')) {
result = _formatSecond(value, result, locale);
}
// format second text
if (format.contains('a')) {
result = _formatAmpm(value, result, locale);
}
if (result == format) {
return value.toString();
}
Expand Down Expand Up @@ -189,11 +197,17 @@ class DateTimeFormatter {
}

/// format hour text
static String _formatHour(
int value, String format, DateTimePickerLocale locale) {
static String _format24Hour(
int value, String format, DateTimePickerLocale locale) {
return _formatNumber(value, format, 'H');
}

/// format hour text
static String _format12Hour(
int value, String format, DateTimePickerLocale locale) {
return _formatNumber(value % 12 == 0 ? 12 : value % 12, format, 'h');
}

/// format minute text
static String _formatMinute(
int value, String format, DateTimePickerLocale locale) {
Expand All @@ -202,10 +216,19 @@ class DateTimeFormatter {

/// format second text
static String _formatSecond(
int value, String format, DateTimePickerLocale locale) {
int value, String format, DateTimePickerLocale locale) {
return _formatNumber(value, format, 's');
}

/// format ampm text
static String _formatAmpm(
int value, String format, DateTimePickerLocale locale) {
if (value == 0) {
return 'AM';
}
return 'PM';
}

/// format number, if the digit count is 2, will pad zero on the left
static String _formatNumber(int value, String format, String unit) {
if (format.contains('$unit$unit')) {
Expand Down
28 changes: 9 additions & 19 deletions lib/src/widget/date_picker_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,35 +152,26 @@ class _DatePickerWidgetState extends State<DatePickerWidget> {

/// find scroll controller by specified format
FixedExtentScrollController _findScrollCtrl(String format) {
FixedExtentScrollController scrollCtrl;
_scrollCtrlMap.forEach((key, value) {
if (format.contains(key)) {
scrollCtrl = value;
}
});
return scrollCtrl;
String key = _scrollCtrlMap.keys.firstWhere((key) => format.contains(key));

return _scrollCtrlMap[key];
}

/// find item value range by specified format
List<int> _findPickerItemRange(String format) {
List<int> valueRange;
_valueRangeMap.forEach((key, value) {
if (format.contains(key)) {
valueRange = value;
}
});
return valueRange;
String key = _valueRangeMap.keys.firstWhere((key) => format.contains(key));

return _valueRangeMap[key];
}

/// render the picker widget of year、month and day
Widget _renderDatePickerWidget() {
List<Widget> pickers = List<Widget>();
List<String> formatArr =
DateTimeFormatter.splitDateFormat(widget.dateFormat);
formatArr.forEach((format) {
List<Widget> pickers = formatArr.map((format) {
List<int> valueRange = _findPickerItemRange(format);

Widget pickerColumn = _renderDatePickerColumnComponent(
return _renderDatePickerColumnComponent(
scrollCtrl: _findScrollCtrl(format),
valueRange: valueRange,
format: format,
Expand All @@ -194,8 +185,7 @@ class _DatePickerWidgetState extends State<DatePickerWidget> {
}
},
);
pickers.add(pickerColumn);
});
}).toList();
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: pickers);
}
Expand Down
Loading