Hey FlutterFlow fam 👋
Ever had that moment where you carefully crafted a “Save draft before leaving?” dialog, only for Android’s back gesture to yeet it out of existence like it never existed? Yeah… same. FlutterFlow’s “Disable Back Button” toggle works on full pages, but custom dialogs and bottom sheets still get ghosted the second someone swipes back. iOS behaves; Android goes full chaos gremlin.
The fix (and hero of the story): create a NonDismissibleDialogWrapper widget and wrap your dialog with it. It swaps the default pop behavior for this little gem:
Because canPop: false, Android back gestures politely sit in the corner until you tell them they can leave. Now you can wire your own “On Back Button Pressed” action, call a custom action, or make up your own rule like “Only dismiss if user performs the secret triple tap.” Your flow stays intact, users don’t lose progress, and you look like the wizard who made dialogs behave.
Give it a spin, and may your back gestures be forever obedient 😄
Here is helper Code.
class NonDismissibleDialogWrapper extends StatefulWidget {
const NonDismissibleDialogWrapper({
super.key,
this.width,
this.height,
required this.child,
});
final double? width;
final double? height;
final Widget Function() child;
@override
State<NonDismissibleDialogWrapper> createState() =>
_NonDismissibleDialogWrapperState();
}
class _NonDismissibleDialogWrapperState
extends State<NonDismissibleDialogWrapper> {
@override
Widget build(BuildContext context) {
Widget content = widget.child();
if (widget.width != null || widget.height != null) {
content = SizedBox(
width: widget.width,
height: widget.height,
child: content,
);
}
return PopScope(
canPop: false,
child: GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
FocusManager.instance.primaryFocus?.unfocus();
},
child: content,
),
);
}
}