Skip to content

Instantly share code, notes, and snippets.

@plateaukao
Created July 25, 2020 08:58
Show Gist options
  • Save plateaukao/79aa39854dc4eabf1220bdfa9a0334b6 to your computer and use it in GitHub Desktop.
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.
// 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