Skip to content

Instantly share code, notes, and snippets.

@jezell
Created September 4, 2024 02:13
Show Gist options
  • Save jezell/777cc3ca5fb685e899665b3d9b590e9c to your computer and use it in GitHub Desktop.
Save jezell/777cc3ca5fb685e899665b3d9b590e9c to your computer and use it in GitHub Desktop.
Auto Overlay Portal
import "package:flutter/material.dart";
class AutoOverlayPortal extends StatefulWidget {
const AutoOverlayPortal(
{super.key, required this.overlayChildBuilder, this.child});
final Widget Function(BuildContext) overlayChildBuilder;
final Widget? child;
@override
State createState() => _AutoOverlayPortalState();
}
class _AutoOverlayPortalState extends State<AutoOverlayPortal> {
late OverlayPortalController controller;
@override
void initState() {
super.initState();
controller = OverlayPortalController();
controller.show();
}
@override
void dispose() {
super.dispose();
if (controller.isShowing) {
controller.hide();
}
}
@override
Widget build(BuildContext context) {
return OverlayPortal(
controller: controller,
overlayChildBuilder: widget.overlayChildBuilder,
child: widget.child);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment