Native context menu for Flutter apps

Overview

native_context_menu

Native context menu for flutter apps

lesnitsky.dev GitHub stars Twitter Follow

Preview

Installation

flutter pub add native_context_menu

Usage

import 'package:native_context_menu/native_context_menu.dart';
import 'package:flutter/material.dart';

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

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  String? action;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: ContextMenuRegion(
          onDismissed: () => setState(() => action = 'Menu was dismissed'),
          onItemSelected: (item) => setState(() {
            action = '${item.title} was selected';
          }),
          menuItems: [
            MenuItem(title: 'First item'),
            MenuItem(title: 'Second item'),
            MenuItem(
              title: 'Third item with submenu',
              items: [
                MenuItem(title: 'First subitem'),
                MenuItem(title: 'Second subitem'),
                MenuItem(title: 'Third subitem'),
              ],
            ),
            MenuItem(title: 'Fourth item'),
          ],
          child: Card(
            child: Center(
              child: Text(action ?? 'Right click me'),
            ),
          ),
        ),
      ),
    );
  }
}

Platform support

Platform Supported
MacOS
Linux
Windows

License

MIT


lesnitsky.dev GitHub stars Twitter Follow

Issues
  • Add Linux support, refactor Windows & remove dependency upon Dart devicePixelRatio & position

    Add Linux support, refactor Windows & remove dependency upon Dart devicePixelRatio & position

    This PR adds:

    • Linux support.
    • Refactoring of Windows implementation to use InvokeMethod on C++ side to notify about selected menu item. And using GetCursorPos to get position for opening the context menu.
    • Linux & Windows no longer require devicePixelRatio and position arguments (although optional).

    NOTE: I made native code itself find the menu coordinates and show the menu accordingly.

    I noticed that you are passing the context menu coordinates from Dart (which is perfectly fine), so I declared an optional macro USE_FLUTTER_POSITION to use those coordinates on Linux instead of using GTK's method (to use it just add #define USE_FLUTTER_POSITION at the start of the file). I do not recommend this however since it was causing problems for me on the Wayland.

    I believe code is nicely arranged (follows Google C++ Style Guide) & I have added good amount of comments explaining everything.

    https://user-images.githubusercontent.com/28951144/135107609-8f02281a-3492-4f22-a09a-7425d4980dee.mp4

    opened by alexmercerind 4
  • Add Linux support & refactor Windows

    Add Linux support & refactor Windows

    This PR adds:

    • Linux support to the plugin.
    • Refactored Windows implementation, to use InvokeMethod on C++ side to notify about selected menu item. And using GetCursorPos to get position for opening the context menu.
    • Now passing devicePixelRatio and position arguments (from Dart) will result in context menu shown at the passed position, otherwise at the cursor position.
    • Following Google C++ Style Guide on Windows & Linux.
    • Other changes proposed from: #7.

    Screenshot_20211001_134609

    EDIT: I will be glad if this my contribution gets counted for Hacktoberfest's criteria of having hacktoberfest-accepted label on this PR. 😄

    opened by alexmercerind 2
  • Add a longer description to pubspec.yaml

    Add a longer description to pubspec.yaml

    This PR adds a longer description to pubspec.yaml to add another 10 points to the pub.dev score.

    It also updates .gitignore to ignore IntelliJ configuration files.

    opened by GroovinChip 1
  • Federalize the plugin

    Federalize the plugin

    Since there are some different context menu APIs in some platforms (eg. Windows, see #2), a federalized plugin could take advantage of its flexibility on having multiple platform implementations.

    opened by renancaraujo 1
  • Add support for disabling menu items on macos

    Add support for disabling menu items on macos

    This PR addresses https://github.com/lesnitsky/native_context_menu/issues/11 on macos. A couple of important notes:

    • There's an onSelected function on MenuItem that doesn't seem like it is used at the moment. It was a bit unclear what the difference was designed to be between this callback and onItemSelected in ContextMenuRegion. My assumption is that I'd use the former if I wanted different functions to be called back for each item, and I'd use the latter if I just wanted to have one function (and if both were present, then both would be called). However, as I mentioned, MenuItem.onSelected isn't currently hooked up, so I had to add a call to ContextMenuRegion to make sure it calls both. This assumption may not be correct, but was important for my decision on how to enable/disable each item.
    • I consider adding a separate flag called isEnabled defaulting to true, however, I ended adopting the Flutter convention of disabling the widget if the onSelected function is not set. However, this would be a breaking change for any current users of this library (all menu items would be disabled unless they were setting the onSelected in their MenuItem objects - which they wouldn't be because those callbacks don't currently get called)

    Windows and Linux have not been touched.

    opened by edwardaux 1
Owner
Andrei Lesnitsky
Open Source Software Engineer @invertase
Andrei Lesnitsky
Plays native alert sound and shows native dialogs/alerts in your Flutter app.

flutter_platform_alert 2021 © Weizhong Yang a.k.a zonble. A simple plugin to present native alerts, including playing alert sounds and showing alert d

Weizhong Yang a.k.a zonble 46 May 9, 2022
This plugin allows Flutter desktop apps to defines system tray.

tray_manager This plugin allows Flutter desktop apps to defines system tray. tray_manager Platform Support Quick Start Installation ⚠️ Linux requireme

LeanFlutter 54 May 8, 2022
This plugin allows Flutter desktop apps to Auto launch on startup / login.

This plugin allows Flutter desktop apps to Auto launch on startup / login.

LeanFlutter 25 May 8, 2022
This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).

hotkey_manager This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut). hotkey_manager Platform Support Quick Star

LeanFlutter 55 May 2, 2022
A Flutter package that makes it easy to customize and work with your Flutter desktop app's system tray.

system_tray A Flutter package that that enables support for system tray menu for desktop flutter apps. on Windows, macOS and Linux. Features: - Modify

AnTler 97 Apr 27, 2022
Flutter-Clock-and-Reminder-App - a highly functional clock and reminder app developed on flutter framework.

clock_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

Umar Baloch 5 Dec 27, 2021
A framework for building native Windows apps with React.

React Native for Windows Build native Windows apps with React. See the official React Native website for an introduction to React Native. React Native

Microsoft 14.7k May 11, 2022
A native textfield that can be used in place of Flutter's TextField widget.

Better Textfield A native textfield that can be used in place of Flutter's TextField widget. Demo demo.mp4 Here are some screenshots of the demo app:

Abhay Maurya 2 Jan 23, 2022
Acrylic effect for all existing Win32 context menus

AcrylicMenus This is a proof-of-concept tiny application that applies acrylic effect to almost all existing Win32 context menus on Windows 10 and Wind

null 247 May 10, 2022
Detect-KeAttachProcess by iterating through all processes as well as checking the context of the thread.

Detect-KeAttachProcess Detect-KeAttachProcess - by iterating through all processes as well as checking the context of the thread. Recently I started s

null 72 May 1, 2022
Visual Studio native debugger extension to help debug native applications using Mono.

Unity Mixed Callstack UnityMixedCallstack is a Visual Studio 2017/2019 extension to help debug native applications embedding Mono, like Unity. If you

Unity Technologies 66 Apr 1, 2022
A customized LGL Android mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android

PUBG Mobile ESP Mod Menu A customized LGL mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android. Everything are fixed so it works with both

null 42 Mar 19, 2022
Portal 2/Portal Reloaded internal cheat sdk with imgui-based menu

portal2-internal A simple Portal 2/Portal Reloaded internal cheat base with imgui-based menu coded in a few days because why not Features: simple menu

es3n1n 21 Apr 10, 2022
Install the Homebrew Channel to the vWii Menu from Wii U Mode.

Install a channel to the vWii Menu from Wii U Mode. In its current state, it simply installs the Homebrew Channel.

Puzzle 21 Mar 26, 2022
api & source menu base import imgui from imgui-js

onetap v4 crack https://discord.gg/AXCtxVH4PB people asking me for otv4 source "bin2h" (meaning binary to hex) large hexadecimal array deleted all the

h4xr0x#1337 7 Apr 15, 2022
Very minimalistic UEFI boot menu / Stivale2 bootloader

Tosaithe Tosaithe is a minimalistic UEFI-firmware menu/bootloader. It can chain-load other EFI programs and loaders, including Linux kernels, and has

Davin McCall 10 Apr 28, 2022
ColecoAdam a boot menu and configurator for ADE virtual drives

VHS HEAD For Coleco Adam users with Adamnet Disk Emulator (ADE) devices. VHS Head is a boot menu and configuration program for ADE (Pro and Lite) user

Thomas Cherryhomes 3 Dec 24, 2021
Coco External GTA5 Mod Menu

Coco External GTA5 Mod Menu DISCLAIMER: This program is purely for Educational and Evaluation purposes ONLY. Be aware that I am not responsible for an

Colton Kennedy 4 Oct 13, 2021
[PS3] Bo1 Mod Menu Jo-Milk's Playground V2... I never finished this project what a shame... works on HEN

-PS3-Bo1-Mod-Menu-Jo-Milk-s-Playground-V2 [PS3] Bo1 Mod Menu Jo-Milk's Playground V2... I never finished this project what a shame... works on HEN Ple

Jo-Milk 4 May 3, 2022