Skip to content

Commit

Permalink
Merge pull request #13 from wisemen-digital/feature/inline-date-picker
Browse files Browse the repository at this point in the history
Change showPlatformDatePicker to use the new style datePicker.
  • Loading branch information
Yani-Maassen committed Jul 10, 2024
2 parents b742eb4 + 8d76d83 commit 7d6cd03
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 81 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.16

* Changed `showPlatformDatePicker` to make use of the new iOS date picker style.

## 1.0.15

* Added a `PlatformSearchBar` and created a `SearchAppBarScaffold` for use when needing a large AppBar with search.
Expand Down
23 changes: 1 addition & 22 deletions ios/Classes/FLDatePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FLDatePicker: NSObject, FlutterPlatformView {
) {
let argsDict = args as! Dictionary<String, Any>;
let picker = UIDatePicker(frame: frame)
picker.preferredDatePickerStyle = .compact
picker.preferredDatePickerStyle = .inline
picker.datePickerMode = UIDatePicker.Mode(rawValue: argsDict["mode"] as! Int)!
if let dateStr = argsDict["date"] as? String {
picker.date = FLDatePicker.inDateFormatter.date(from: dateStr) ?? Date()
Expand All @@ -39,27 +39,6 @@ class FLDatePicker: NSObject, FlutterPlatformView {
if let localeStr = argsDict["locale"] as? String {
picker.locale = Locale(identifier: localeStr)
}
if let backgroundColorStr = argsDict["backgroundColor"] as? String {
if let bgView = picker.subviews.first?.subviews.first?.subviews.first {
bgView.backgroundColor = UIColor(hexString: backgroundColorStr)
backgroundColor = bgView.backgroundColor
}
}
if let borderColorStr = argsDict["borderColor"] as? String {
if let bgView = picker.subviews.first?.subviews.first?.subviews.first {
bgView.layer.borderColor = UIColor(hexString: borderColorStr)?.cgColor
}
}
if let borderWidth = argsDict["borderWidth"] as? CGFloat {
if let bgView = picker.subviews.first?.subviews.first?.subviews.first {
bgView.layer.borderWidth = borderWidth
}
}
if let cornerRadius = argsDict["cornerRadius"] as? CGFloat {
if let bgView = picker.subviews.first?.subviews.first?.subviews.first {
bgView.layer.cornerRadius = cornerRadius
}
}
if let fontSize = argsDict["fontSize"] as? CGFloat {
if let lblView = picker.subviews.first?.subviews.first?.subviews[1] {
lblView.setValue(UIFont.systemFont(ofSize: fontSize), forKey: "font")
Expand Down
111 changes: 66 additions & 45 deletions lib/helpers/date_picker_helper.dart
Original file line number Diff line number Diff line change
@@ -1,66 +1,87 @@
import 'dart:io';
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wisewidgetslibrary/constants/platform_constants.dart';
import 'package:wisewidgetslibrary/s_core_localizations/s_core_localizations.dart';
import 'package:wisewidgetslibrary/wise_widgets_library.dart';

Future<DateTime?> showPlatformDatePicker({
required BuildContext context,
DateTime? selectedDate,
DateTime? minDate,
DateTime? maxDate,
Color? color,
Color? backgroundColor = Colors.white,
Color color = Colors.blue,
Color backgroundColor = Colors.white,
}) async {
DateTime? newDate;
newDate ??= DateTime.now();
var isChanged = false;
newDate ??= selectedDate;

if (isIos) {
return showCupertinoModalPopup<DateTime?>(
// ignore: omit_local_variable_types
const double height = 450;
// ignore: omit_local_variable_types
const double maxWidth = 400;
const bottomPadding = 100;

return showDialog(
context: context,
builder: (context) => Container(
height: MediaQuery.of(context).size.height * 0.3,
color: backgroundColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CupertinoButton(
child: Text(Swl.of(context).cancel),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoButton(
child: Text(Swl.of(context).save),
onPressed: () {
if (!isChanged && selectedDate != null) {
newDate = selectedDate;
}
Navigator.of(context).pop(newDate);
},
builder: (context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Center(
child: Dialog(
insetPadding: pad20,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: maxWidth),
child: Container(
height: height,
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: rad16,
),
child: Padding(
padding: pad16,
child: Column(
children: [
SizedBox(
height: height - bottomPadding,
child: UIDatePicker(
tintColor: color,
date: selectedDate,
minimumDate: minDate,
maximumDate: maxDate,
onChanged: (selectedDate) {
newDate = selectedDate;
},
),
),
gapH16,
PlatformButton(
color: color,
height: 48,
cupertinoBorderRadius: rad25,
child: Text(
Swl.of(context).ok,
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'CupertinoSystemDisplay',
fontSize: 15,
color: color.computeLuminance() > 0.5
? Colors.black
: Colors.white,
),
),
onPressed: () => Navigator.of(context).pop(newDate),
),
],
),
),
),
],
),
Flexible(
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (selectedDate) {
isChanged = true;
newDate = selectedDate;
},
minimumDate: minDate,
maximumDate: maxDate,
initialDateTime: selectedDate,
),
),
],
),
),
),
);
},
);
} else {
return showDatePicker(
Expand Down
14 changes: 0 additions & 14 deletions lib/ui_pickers/src/ui_date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ class _UIDatePickerState extends State<UIDatePicker> {
if (widget.tintColor != null) {
creationParams['tintColor'] = widget.tintColor?.value.toRadixString(16);
}
if (widget.backgroundColor != null) {
creationParams['backgroundColor'] =
widget.backgroundColor?.value.toRadixString(16);
}
if (widget.borderColor != null) {
creationParams['borderColor'] =
widget.borderColor?.value.toRadixString(16);
}
if (widget.borderWidth != null) {
creationParams['borderWidth'] = widget.borderWidth;
}
if (widget.cornerRadius != null) {
creationParams['cornerRadius'] = widget.cornerRadius;
}
if (widget.fontSize != null) {
creationParams['fontSize'] = widget.fontSize;
}
Expand Down

0 comments on commit 7d6cd03

Please sign in to comment.