Skip to content

Commit

Permalink
docs(example): make context menu usable through leanflutter/window_ma…
Browse files Browse the repository at this point in the history
…nager
  • Loading branch information
benthillerkus committed May 16, 2022
1 parent 9704cf6 commit 37d0789
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
18 changes: 16 additions & 2 deletions example/select_image/lib/main.dart
Expand Up @@ -9,8 +9,18 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' hide MenuItem;
import 'package:image/image.dart' as img;
import 'package:window_manager/window_manager.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();

WindowOptions windowOptions = WindowOptions(
backgroundColor: Colors.green,
skipTaskbar: false,
);
windowManager.waitUntilReadyToShow(windowOptions, windowManager.show);

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

Expand Down Expand Up @@ -156,11 +166,15 @@ class _HomeScreenState extends State<HomeScreen> {
final name = element.name ?? element.key.toString();
_icon.setTooltip(name);
_icon.setImage(delegate: element.delegate);
_icon.onTap = (_) => windowManager.show();
_icon.onSecondaryTap = (_) => popUpContextualMenu(
Menu(items: [
MenuItem(label: "select_image example app", sublabel: name),
MenuItem.separator(),
MenuItem(label: "Exit")
MenuItem(
label: "Exit",
toolTip: "Closes the App",
onClick: (_) => windowManager.close())
]),
placement: Placement.bottomLeft);
_icon.show();
Expand Down
7 changes: 7 additions & 0 deletions example/select_image/pubspec.lock
Expand Up @@ -266,6 +266,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
window_manager:
dependency: "direct main"
description:
name: window_manager
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.3"
xml:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions example/select_image/pubspec.yaml
Expand Up @@ -20,6 +20,7 @@ dependencies:
file_picker: ^4.5.1
image: ^3.1.3
contextual_menu: ^0.1.1
window_manager: ^0.2.3

dev_dependencies:
flutter_test:
Expand Down
Expand Up @@ -8,10 +8,13 @@

#include <betrayal/betrayal_plugin.h>
#include <contextual_menu/contextual_menu_plugin.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
BetrayalPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BetrayalPlugin"));
ContextualMenuPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ContextualMenuPlugin"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
Expand Up @@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
betrayal
contextual_menu
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 37d0789

Please sign in to comment.