Skip to content

Commit d915e9f

Browse files
committed
fix: Properly disable date and time pickers when onChanged is null (Fixes #1210)
1 parent 5e7e188 commit d915e9f

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- fix: Custom `ContextMenuButtonItem` are correctly displayed on text selection control ([#1212](https://github.com/bdlukaa/fluent_ui/pull/1212))
66
- fix: `TreeView`'s focus always starts at first or last item ([#834](https://github.com/bdlukaa/fluent_ui/issues/834), [#1195](https://github.com/bdlukaa/fluent_ui/pull/1195))
77
- fix: `InfoBar` no longer throw error when automatically closing ([#955](https://github.com/bdlukaa/fluent_ui/issues/955), [#1215](https://github.com/bdlukaa/fluent_ui/pull/1215))
8+
- fix: Properly disable date and time pickers when `onChanged` is null ([#1210](https://github.com/bdlukaa/fluent_ui/issues/1210))
89

910
## 4.11.3
1011

lib/src/controls/form/number_box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ class NumberBoxState<T extends num> extends State<NumberBox<T>> {
701701
value = num.tryParse(controller.text);
702702
if (value == null && widget.allowExpressions) {
703703
try {
704-
value = Parser()
704+
value = ShuntingYardParser()
705705
.parse(controller.text)
706706
.evaluate(EvaluationType.REAL, ContextModel());
707707
// If the value is infinite or not a number, we reset the value with

lib/src/controls/pickers/date_picker.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ class DatePicker extends StatefulWidget {
8383

8484
/// Whenever the current selected date is changed by the user.
8585
///
86-
/// If null, the picker is considered disabled
86+
/// If `null`, the picker is considered disabled
8787
final ValueChanged<DateTime>? onChanged;
8888

89-
/// Whenever the user cancels the date change.
89+
/// Called when the user cancels the picker.
9090
final VoidCallback? onCancel;
9191

9292
/// The content of the header
@@ -330,16 +330,15 @@ class DatePickerState extends State<DatePicker> {
330330
child: (context, open) => HoverButton(
331331
autofocus: widget.autofocus,
332332
focusNode: widget.focusNode,
333-
onPressed: () async {
334-
_monthController.dispose();
335-
// _monthController = null;
336-
_dayController.dispose();
337-
// _dayController = null;
338-
_yearController.dispose();
339-
// _yearController = null;
340-
initControllers();
341-
await open();
342-
},
333+
onPressed: widget.onChanged == null
334+
? null
335+
: () async {
336+
_monthController.dispose();
337+
_dayController.dispose();
338+
_yearController.dispose();
339+
initControllers();
340+
await open();
341+
},
343342
builder: (context, states) {
344343
if (states.isDisabled) states = <WidgetState>{};
345344
const divider = Divider(

lib/src/controls/pickers/time_picker.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,15 @@ class TimePickerState extends State<TimePicker>
242242
child: (context, open) => HoverButton(
243243
focusNode: widget.focusNode,
244244
autofocus: widget.autofocus,
245-
onPressed: () async {
246-
_hourController.dispose();
247-
_minuteController.dispose();
248-
_amPmController.dispose();
249-
initControllers();
250-
await open();
251-
},
245+
onPressed: widget.onChanged == null
246+
? null
247+
: () async {
248+
_hourController.dispose();
249+
_minuteController.dispose();
250+
_amPmController.dispose();
251+
initControllers();
252+
await open();
253+
},
252254
builder: (context, states) {
253255
const divider = Divider(
254256
direction: Axis.vertical,

0 commit comments

Comments
 (0)