Created
July 25, 2020 08:58
-
-
Save plateaukao/79aa39854dc4eabf1220bdfa9a0334b6 to your computer and use it in GitHub Desktop.
A dart code snippet to support longpress display popup dialog feature, when finger leaves, the popup will be closed too.
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
// Implement a function to create OverlayEntry | |
OverlayEntry getMyOverlayEntry({ | |
@required BuildContext context, | |
SomeData someData, | |
}) { | |
return OverlayEntry( | |
builder: (context) { | |
return AlertDialog(child: SomeWidgetAgain()); | |
} | |
); | |
} | |
// In the widget where you want to support long press feature | |
OverlayEntry myOverayEntry; | |
GestureDetector( | |
onLongPress: () { | |
myOverayEntry = getMyOverlayEntry(context: context, someData: someData); | |
Overlay.of(context).insert(myOverayEntry); | |
}, | |
onLongPressEnd: (details) => myOverayEntry?.remove(), | |
child: SomeWidgerHere(), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment