ios_adaptive_context_menu 0.1.0
ios_adaptive_context_menu: ^0.1.0 copied to clipboard
Flutter plugin to show a native iOS context menu on single tap.
import 'package:flutter/material.dart';
import 'package:ios_adaptive_context_menu/ios_adaptive_context_menu.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'ios_adaptive_context_menu example',
home: const ContextMenuExamplePage(),
);
}
}
class ContextMenuExamplePage extends StatefulWidget {
const ContextMenuExamplePage({super.key});
@override
State<ContextMenuExamplePage> createState() => _ContextMenuExamplePageState();
}
class _ContextMenuExamplePageState extends State<ContextMenuExamplePage> {
String _selectedId = 'none';
List<IosContextMenuItem> get _actions => <IosContextMenuItem>[
const IosContextMenuSubmenu(
title: 'Share',
iconSystemName: 'square.and.arrow.up',
iconAssetPath: MediaRes.share,
children: <IosContextMenuItem>[
IosContextMenuAction(
id: 'share_meal',
title: 'Share meal',
iconSystemName: 'square.and.arrow.up',
iconAssetPath: MediaRes.share,
),
],
),
const IosContextMenuDivider(),
const IosContextMenuAction(
id: 'saveasrecipe',
title: 'Save as recipe',
iconSystemName: 'book.closed',
iconAssetPath: MediaRes.share,
),
const IosContextMenuDivider(),
const IosContextMenuAction(
id: 'clr',
title: 'Clear meal',
destructive: true,
iconSystemName: 'trash',
iconAssetPath: MediaRes.share,
),
const IosContextMenuAction(
id: 'rpt',
title: 'Repeat meal',
iconSystemName: 'repeat',
iconAssetPath: MediaRes.share,
),
const IosContextMenuAction(
id: 'pst',
title: 'Paste',
iconSystemName: 'document.on.clipboard',
iconAssetPath: MediaRes.share,
),
const IosContextMenuAction(
id: 'cp',
title: 'Copy',
iconSystemName: 'pip',
iconAssetPath: MediaRes.share,
),
];
TextStyle appStyle({
required Color color,
required FontWeight fw,
required double size,
}) {
return TextStyle(color: color, fontWeight: fw, fontSize: size);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Single Tap Context Menu')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IosSingleTapContextMenu(
actions: _actions,
onSelected: (String id) {
setState(() {
_selectedId = id;
});
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Selected action: $id')));
},
child: Text(
'Open Context Menu',
style: appStyle(
color: Colors.black,
fw: FontWeight.bold,
size: 32,
),
),
),
],
),
),
);
}
}
class MediaRes {
const MediaRes._();
static const String share = 'assets/share.svg';
}