Skip to content

Commit 1482f8a

Browse files
committed
Fix updating text if showTime updates
1 parent 6d2201d commit 1482f8a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/material_leap/lib/src/widgets/date_time_field.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,35 @@ class _DateTimeFieldState extends State<DateTimeField> {
4343
WidgetsBinding.instance.addPostFrameCallback((_) => setup());
4444
}
4545

46+
@override
47+
void didUpdateWidget(covariant DateTimeField oldWidget) {
48+
super.didUpdateWidget(oldWidget);
49+
if (oldWidget.initialValue != widget.initialValue) {
50+
_value = widget.initialValue;
51+
_updateText();
52+
}
53+
if (oldWidget.showTime != widget.showTime) {
54+
_updateText();
55+
}
56+
}
57+
58+
void _updateText() {
59+
_controller.text = _value == null ? '' : _format(_value!);
60+
}
61+
4662
void setup() {
4763
_locale = Localizations.localeOf(context).languageCode;
4864
initializeDateFormatting(_locale);
4965
_dateFormat = DateFormat.yMd(_locale);
5066
_timeFormat = DateFormat.Hm(_locale);
51-
_controller.text = _value == null ? '' : _format(_value!);
67+
_updateText();
5268
}
5369

5470
void _change(DateTime? value) {
5571
setState(() {
5672
_value = value;
5773
});
58-
_controller.text = _value == null ? '' : _format(_value!);
74+
_updateText();
5975
widget.onChanged(value);
6076
}
6177

0 commit comments

Comments
 (0)