Flutter CupertinoContextMenu | Popup Menus on Long Press
import 'package:flutter/cupertino.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const CupertinoApp(
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar:
const CupertinoNavigationBar(middle: Text('Cupertino Menus')),
child: SafeArea(
child: CupertinoContextMenu(
actions: [
CupertinoContextMenuAction(
child: const Text('Add to Favorites'),
onPressed: () {
debugPrint('Added to Favorites');
Navigator.of(context).pop();
},
),
CupertinoContextMenuAction(
child: const Text('Download'),
onPressed: () {
debugPrint('Downloaded');
Navigator.of(context).pop();
},
),
CupertinoContextMenuAction(
child: const Text('Report this image'),
onPressed: () {
debugPrint('Reported');
Navigator.of(context).pop();
},
)
], child: Image.network(
width:double.maxFinite,
'https://yt3.ggpht.com/ytc/AMLnZu-glyOmP6yPsxdYUjvCDT5kpLx9NgVIFqnFBTUr=s176-c-k-c0x00ffffff-no-rj'),
)
),
);
}
}