Created
September 4, 2024 02:13
-
-
Save jezell/777cc3ca5fb685e899665b3d9b590e9c to your computer and use it in GitHub Desktop.
Auto Overlay Portal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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