context_menu_macos 0.0.1 copy "context_menu_macos: ^0.0.1" to clipboard
context_menu_macos: ^0.0.1 copied to clipboard

MacOS-style context menu for flutter.

example/lib/main.dart

import 'package:context_menu_macos/context_menu_macos.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: ContextMenuExample(),
      ),
    );
  }
}

class ContextMenuExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          GestureDetector(
            onSecondaryTapDown: (details) {
              showMacosContextMenu(
                context: context,
                globalPosition: details.globalPosition,
                children: [
                  MacosContextMenuItem(
                    content: Text('Copy'),
                    trailing: Text('⌘ C'),
                    onTap: () => Navigator.of(context).pop(),
                  ),
                  MacosContextMenuItem(
                    content: Text('Paste'),
                    trailing: Text('⌘ V'),
                    onTap: () => Navigator.of(context).pop(),
                  ),
                  MacosContextMenuItem(
                    content: Text('Select All'),
                    trailing: Text('⌘ A'),
                    onTap: () => Navigator.of(context).pop(),
                  ),
                  MacosContextMenuDivider(),
                  MacosContextMenuItem(
                    content: Text('Clear'),
                    trailing: Text('⌘ K'),
                    onTap: () => Navigator.of(context).pop(),
                  ),
                  MacosContextMenuDivider(),
                  MacosContextMenuItem(
                    content: Text('Kill'),
                    onTap: () => Navigator.of(context).pop(),
                  ),
                ],
              );
            },
            child: Container(
              width: 100,
              height: 70,
              color: Colors.blue,
              child: Text('click me'),
            ),
          ),
        ],
      ),
    );
  }
}
1
likes
80
pub points
50%
popularity

Publisher

unverified uploader

MacOS-style context menu for flutter.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on context_menu_macos