As far as I know, you can't do that with Dialog because Dialog use Navigator, which use Stack only allow you to push and pop the top Route
Another option you can use to implement this is OverLayEntry, like this:
class _MyHomePageState extends State<MyHomePage> {
OverlayEntry? _overlayEntry1;
OverlayEntry? _overlayEntry2;
@override
void initState() {
super.initState();
_overlayEntry1 = OverlayEntry(
builder: (context) {
return Material(
color: Colors.transparent,
child: Center(
child: Container(
height: 300,
width: 300,
color: Colors.green,
),
),
);
},
);
_overlayEntry2 = OverlayEntry(
builder: (context) {
return Material(
color: Colors.transparent,
child: Center(
child: InkWell(
onTap: () {
_overlayEntry1?.remove();
},
child: Container(
height: 150,
width: 150,
color: Colors.red,
),
),
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: InkWell(
onTap: () {
Overlay.of(context)!.insert(_overlayEntry1!);
Overlay.of(context)!.insert(_overlayEntry2!);
},
child: Text('Show overlay'),
),
),
);
}
}