Skip to content

Commit d02f9d7

Browse files
Fix AlertDialog broken content when testing in Flet app (#2192)
* Fix AlertDialog broken content when testing in Flet app Fix #2073 * Do not use root navigator and date and time pickers * Cleanup
1 parent dfe9b4e commit d02f9d7

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

package/lib/src/controls/alert_dialog.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ class AlertDialogControl extends StatefulWidget {
2020
final Widget? nextChild;
2121

2222
const AlertDialogControl(
23-
{Key? key,
23+
{super.key,
2424
this.parent,
2525
required this.control,
2626
required this.children,
2727
required this.parentDisabled,
28-
required this.nextChild})
29-
: super(key: key);
28+
required this.nextChild});
3029

3130
@override
3231
State<AlertDialogControl> createState() => _AlertDialogControlState();
@@ -96,16 +95,17 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
9695

9796
// close previous dialog
9897
if (ModalRoute.of(context)?.isCurrent != true) {
99-
Navigator.pop(context);
98+
Navigator.of(context).pop();
10099
}
101100

102101
widget.control.state["open"] = open;
103102

104103
WidgetsBinding.instance.addPostFrameCallback((_) {
105104
showDialog(
106105
barrierDismissible: !modal,
106+
useRootNavigator: false,
107107
context: context,
108-
builder: (context) => _createAlertDialog()).then((value) {
108+
builder: (context) => dialog).then((value) {
109109
lastOpen = widget.control.state["open"] ?? false;
110110
debugPrint("Dialog should be dismissed ($hashCode): $lastOpen");
111111
bool shouldDismiss = lastOpen;
@@ -126,7 +126,7 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
126126
});
127127
});
128128
} else if (open != lastOpen && lastOpen) {
129-
Navigator.pop(context);
129+
Navigator.of(context).pop();
130130
}
131131

132132
return widget.nextChild ?? const SizedBox.shrink();

package/lib/src/controls/bottom_sheet.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ class BottomSheetControl extends StatefulWidget {
1717
final Widget? nextChild;
1818

1919
const BottomSheetControl(
20-
{Key? key,
20+
{super.key,
2121
this.parent,
2222
required this.control,
2323
required this.children,
2424
required this.parentDisabled,
2525
required this.dispatch,
26-
required this.nextChild})
27-
: super(key: key);
26+
required this.nextChild});
2827

2928
@override
3029
State<BottomSheetControl> createState() => _BottomSheetControlState();
@@ -119,7 +118,7 @@ class _BottomSheetControlState extends State<BottomSheetControl> {
119118
});
120119
});
121120
} else if (open != lastOpen && lastOpen) {
122-
Navigator.pop(context);
121+
Navigator.of(context).pop();
123122
}
124123

125124
return const SizedBox.shrink();

package/lib/src/controls/date_picker.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class DatePickerControl extends StatefulWidget {
1515
final dynamic dispatch;
1616

1717
const DatePickerControl({
18-
Key? key,
18+
super.key,
1919
this.parent,
2020
required this.control,
2121
required this.children,
2222
required this.parentDisabled,
2323
required this.dispatch,
24-
}) : super(key: key);
24+
});
2525

2626
@override
2727
State<DatePickerControl> createState() => _DatePickerControlState();
@@ -137,6 +137,7 @@ class _DatePickerControlState extends State<DatePickerControl> {
137137

138138
WidgetsBinding.instance.addPostFrameCallback((_) {
139139
showDialog<DateTime>(
140+
useRootNavigator: false,
140141
context: context,
141142
builder: (context) => createSelectDateDialog()).then((result) {
142143
debugPrint("pickDate() completed");

package/lib/src/controls/time_picker.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class TimePickerControl extends StatefulWidget {
1313
final dynamic dispatch;
1414

1515
const TimePickerControl({
16-
Key? key,
16+
super.key,
1717
this.parent,
1818
required this.control,
1919
required this.children,
2020
required this.parentDisabled,
2121
required this.dispatch,
22-
}) : super(key: key);
22+
});
2323

2424
@override
2525
State<TimePickerControl> createState() => _TimePickerControlState();
@@ -97,6 +97,7 @@ class _TimePickerControlState extends State<TimePickerControl> {
9797

9898
WidgetsBinding.instance.addPostFrameCallback((_) {
9999
showDialog<TimeOfDay>(
100+
useRootNavigator: false,
100101
context: context,
101102
builder: (context) => createSelectTimeDialog()).then((result) {
102103
debugPrint("pickTime() completed");

0 commit comments

Comments
 (0)