Skip to content

Commit

Permalink
Fix AlertDialog broken content when testing in Flet app (#2192)
Browse files Browse the repository at this point in the history
* Fix AlertDialog broken content when testing in Flet app

Fix #2073

* Do not use root navigator and date and time pickers

* Cleanup
  • Loading branch information
FeodorFitsner authored Dec 4, 2023
1 parent dfe9b4e commit d02f9d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
12 changes: 6 additions & 6 deletions package/lib/src/controls/alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ class AlertDialogControl extends StatefulWidget {
final Widget? nextChild;

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

@override
State<AlertDialogControl> createState() => _AlertDialogControlState();
Expand Down Expand Up @@ -96,16 +95,17 @@ class _AlertDialogControlState extends State<AlertDialogControl> {

// close previous dialog
if (ModalRoute.of(context)?.isCurrent != true) {
Navigator.pop(context);
Navigator.of(context).pop();
}

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

WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog(
barrierDismissible: !modal,
useRootNavigator: false,
context: context,
builder: (context) => _createAlertDialog()).then((value) {
builder: (context) => dialog).then((value) {
lastOpen = widget.control.state["open"] ?? false;
debugPrint("Dialog should be dismissed ($hashCode): $lastOpen");
bool shouldDismiss = lastOpen;
Expand All @@ -126,7 +126,7 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
});
});
} else if (open != lastOpen && lastOpen) {
Navigator.pop(context);
Navigator.of(context).pop();
}

return widget.nextChild ?? const SizedBox.shrink();
Expand Down
7 changes: 3 additions & 4 deletions package/lib/src/controls/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ class BottomSheetControl extends StatefulWidget {
final Widget? nextChild;

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

@override
State<BottomSheetControl> createState() => _BottomSheetControlState();
Expand Down Expand Up @@ -119,7 +118,7 @@ class _BottomSheetControlState extends State<BottomSheetControl> {
});
});
} else if (open != lastOpen && lastOpen) {
Navigator.pop(context);
Navigator.of(context).pop();
}

return const SizedBox.shrink();
Expand Down
5 changes: 3 additions & 2 deletions package/lib/src/controls/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class DatePickerControl extends StatefulWidget {
final dynamic dispatch;

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

@override
State<DatePickerControl> createState() => _DatePickerControlState();
Expand Down Expand Up @@ -137,6 +137,7 @@ class _DatePickerControlState extends State<DatePickerControl> {

WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog<DateTime>(
useRootNavigator: false,
context: context,
builder: (context) => createSelectDateDialog()).then((result) {
debugPrint("pickDate() completed");
Expand Down
5 changes: 3 additions & 2 deletions package/lib/src/controls/time_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class TimePickerControl extends StatefulWidget {
final dynamic dispatch;

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

@override
State<TimePickerControl> createState() => _TimePickerControlState();
Expand Down Expand Up @@ -97,6 +97,7 @@ class _TimePickerControlState extends State<TimePickerControl> {

WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog<TimeOfDay>(
useRootNavigator: false,
context: context,
builder: (context) => createSelectTimeDialog()).then((result) {
debugPrint("pickTime() completed");
Expand Down

0 comments on commit d02f9d7

Please sign in to comment.