Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d72857e
date_picker from commit 0402e56
InesaFitsner Oct 19, 2023
53fce41
date_picker.py
InesaFitsner Oct 19, 2023
5846b19
fixed control name, datepicker is shown in test
InesaFitsner Oct 19, 2023
8001149
fixed lastdate
InesaFitsner Oct 24, 2023
2434197
Fixed value getter
FeodorFitsner Oct 24, 2023
824c61f
removed StoreConnector and pass dispatch into constructor instead
InesaFitsner Oct 25, 2023
1bd4ca1
changed attr name to 'onChange' as in dart
InesaFitsner Oct 25, 2023
82ee206
refactor
InesaFitsner Oct 25, 2023
1adb93c
refactor
InesaFitsner Oct 25, 2023
6b34207
on_dismiss event
InesaFitsner Oct 25, 2023
92bc2fa
current_date
InesaFitsner Oct 25, 2023
e185726
error_format_text, error_invalid_text
InesaFitsner Oct 26, 2023
a220d1c
refactor
InesaFitsner Oct 26, 2023
caa09ca
field_hint_text, field_label_text
InesaFitsner Oct 26, 2023
f30b32f
fixed datePickerEntryMode and datePickerMode
InesaFitsner Oct 26, 2023
153a4c6
default value to current_date
InesaFitsner Oct 26, 2023
1d70859
refactor
InesaFitsner Oct 26, 2023
736665c
commented locale parts
InesaFitsner Oct 26, 2023
c9ce232
switch calendar and input icons
InesaFitsner Oct 27, 2023
ec6fdf3
updated control description
InesaFitsner Oct 27, 2023
ef79bf9
refactor
InesaFitsner Oct 31, 2023
a22215f
fixed switchToCalendarEntryModeIcon and switchToInputEntryModeIcon
InesaFitsner Oct 31, 2023
16fbbcb
removed comments
InesaFitsner Oct 31, 2023
4797b04
removed DatePickerState
InesaFitsner Oct 31, 2023
2a50a18
updated enum properties
InesaFitsner Oct 31, 2023
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
9 changes: 9 additions & 0 deletions package/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'clipboard.dart';
import 'column.dart';
import 'container.dart';
import 'datatable.dart';
import 'date_picker.dart';
import 'divider.dart';
import 'drag_target.dart';
import 'draggable.dart';
Expand Down Expand Up @@ -302,6 +303,14 @@ Widget createWidget(Key? key, ControlViewModel controlView, Control? parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled);
case "datepicker":
return DatePickerControl(
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
dispatch: controlView.dispatch,
);
case "draggable":
return DraggableControl(
key: key,
Expand Down
146 changes: 146 additions & 0 deletions package/lib/src/controls/date_picker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import 'package:flutter/material.dart';
import '../actions.dart';
import '../flet_app_services.dart';
import '../models/control.dart';
import '../protocol/update_control_props_payload.dart';
import 'form_field.dart';
import '../utils/icons.dart';

class DatePickerControl extends StatefulWidget {
final Control? parent;
final Control control;
final List<Control> children;
final bool parentDisabled;
final dynamic dispatch;

const DatePickerControl({
Key? key,
this.parent,
required this.control,
required this.children,
required this.parentDisabled,
required this.dispatch,
}) : super(key: key);

@override
State<DatePickerControl> createState() => _DatePickerControlState();
}

class _DatePickerControlState extends State<DatePickerControl> {
bool _open = false;

@override
Widget build(BuildContext context) {
debugPrint("DatePicker build: ${widget.control.id}");
var open = widget.control.attrBool("open", false)!;
DateTime? value = widget.control.attrDateTime("value");
DateTime? firstDate = widget.control.attrDateTime("firstDate");
DateTime? lastDate = widget.control.attrDateTime("lastDate");
DateTime? currentDate = widget.control.attrDateTime("currentDate");
//String? localeString = widget.control.attrString("locale");
String? helpText = widget.control.attrString("helpText");
String? cancelText = widget.control.attrString("cancelText");
String? confirmText = widget.control.attrString("confirmText");
String? errorFormatText = widget.control.attrString("errorFormatText");
String? errorInvalidText = widget.control.attrString("errorInvalidText");
TextInputType keyboardType =
parseTextInputType(widget.control.attrString("keyboardType", "")!);
DatePickerMode datePickerMode = DatePickerMode.values.firstWhere(
(a) =>
a.name.toLowerCase() ==
widget.control.attrString("datePickerMode", "")!.toLowerCase(),
orElse: () => DatePickerMode.day);
DatePickerEntryMode datePickerEntryMode = DatePickerEntryMode.values
.firstWhere(
(a) =>
a.name.toLowerCase() ==
widget.control
.attrString("datePickerEntryMode", "")!
.toLowerCase(),
orElse: () => DatePickerEntryMode.calendar);
String? fieldHintText = widget.control.attrString("fieldHintText");
String? fieldLabelText = widget.control.attrString("fieldLabelText");
IconData? switchToCalendarEntryModeIcon = getMaterialIcon(
widget.control.attrString("switchToCalendarEntryModeIcon", "")!);
IconData? switchToInputEntryModeIcon = getMaterialIcon(
widget.control.attrString("switchToInputEntryModeIcon", "")!);

//Locale locale;
// if (localeString == null) {
// locale = Localizations.localeOf(context);
// } else {
// //locale = Locale(localeString);
// }

void onClosed(DateTime? dateValue) {
String stringValue;
String eventName;
if (dateValue == null) {
stringValue =
value?.toIso8601String() ?? currentDate?.toIso8601String() ?? "";
eventName = "dismiss";
} else {
stringValue = dateValue?.toIso8601String() ?? "";
eventName = "change";
}
List<Map<String, String>> props = [
{"i": widget.control.id, "value": stringValue, "open": "false"}
];
widget.dispatch(
UpdateControlPropsAction(UpdateControlPropsPayload(props: props)));
FletAppServices.of(context).server.updateControlProps(props: props);

FletAppServices.of(context).server.sendPageEvent(
eventTarget: widget.control.id,
eventName: eventName,
eventData: stringValue);
}

Widget createSelectDateDialog() {
Widget dialog = DatePickerDialog(
initialDate: value ?? currentDate ?? DateTime.now(),
firstDate: firstDate ?? DateTime(1900),
lastDate: lastDate ?? DateTime(2050),
currentDate: currentDate ?? DateTime.now(),
helpText: helpText,
cancelText: cancelText,
confirmText: confirmText,
errorFormatText: errorFormatText,
errorInvalidText: errorInvalidText,
keyboardType: keyboardType,
initialCalendarMode: datePickerMode,
initialEntryMode: datePickerEntryMode,
fieldHintText: fieldHintText,
fieldLabelText: fieldLabelText,
switchToCalendarEntryModeIcon: switchToCalendarEntryModeIcon != null
? Icon(switchToCalendarEntryModeIcon)
: null,
switchToInputEntryModeIcon: switchToInputEntryModeIcon != null
? Icon(switchToInputEntryModeIcon)
: null,
);

// dialog = Localizations.override(
// context: context,
// locale: locale,
// child: dialog,
// );

return dialog;
}

if (open && !_open) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog<DateTime>(
context: context,
builder: (context) => createSelectDateDialog()).then((result) {
debugPrint("pickDate() completed");
onClosed(result);
});
});
}

_open = open;
return const SizedBox.shrink();
}
}
8 changes: 8 additions & 0 deletions package/lib/src/models/control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ class Control extends Equatable {
return defValue;
}

DateTime? attrDateTime(String name, [DateTime? defValue]) {
var value = attrs[name.toLowerCase()];
if (value == null) {
return defValue;
}
return DateTime.parse(value);
}

Control copyWith(
{String? id,
String? pid,
Expand Down
1 change: 1 addition & 0 deletions sdk/python/packages/flet-core/src/flet_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
DataRow,
DataTable,
)
from flet_core.date_picker import DatePicker, DatePickerMode, DatePickerEntryMode
from flet_core.divider import Divider
from flet_core.drag_target import DragTarget, DragTargetAcceptEvent
from flet_core.draggable import Draggable
Expand Down
Loading