Skip to content

Commit

Permalink
docs: demonstrate integration with leanflutter/contextual_menu
Browse files Browse the repository at this point in the history
closes #4
  • Loading branch information
benthillerkus committed May 16, 2022
1 parent c1ad065 commit 9704cf6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ BetrayalLogConfig.level = "OFF";

To learn more about logging in *betrayal* have a look at the implementation in [logging.dart](https://github.com/benthillerkus/betrayal/blob/main/lib/src/logging.dart).

## Why is there no built-in method for opening a context menu?

Because it's unrelated from displaying and managing a tray icon.

There are already great plugins for doing so, such as [leanflutter/contextual_menu](https://github.com/leanflutter/contextual_menu)!<br>
In the [select_image](https://github.com/benthillerkus/betrayal/blob/main/example/select_image) example you can see that it plays well with *betrayal*

## Why are my icons still there after restarting the app?

There is no hook for plugin devs to detect a hot restart. The best we can do is to reset state once the restarted app starts to interact with the library again and to provide an optional reset method users can call before `runApp` runs.
Expand Down
1 change: 1 addition & 0 deletions example/select_image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This example shows you how…

- …to use the imperative api in a more complex application
- …use the `image` library to set any image from disk as a tray icon
- …use the `contextual_menu` library to create a context menu

## WTF is going on in the code?

Expand Down
13 changes: 11 additions & 2 deletions example/select_image/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import 'dart:io';

import 'package:betrayal/betrayal.dart';
import 'package:contextual_menu/contextual_menu.dart';
import 'package:select_image/view/view.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide MenuItem;
import 'package:image/image.dart' as img;

void main() {
Expand Down Expand Up @@ -152,8 +153,16 @@ class _HomeScreenState extends State<HomeScreen> {
}

void _setTrayIcon(MyData element) {
_icon.setTooltip(element.name ?? element.key.toString());
final name = element.name ?? element.key.toString();
_icon.setTooltip(name);
_icon.setImage(delegate: element.delegate);
_icon.onSecondaryTap = (_) => popUpContextualMenu(
Menu(items: [
MenuItem(label: "select_image example app", sublabel: name),
MenuItem.separator(),
MenuItem(label: "Exit")
]),
placement: Placement.bottomLeft);
_icon.show();
}
}
Expand Down
14 changes: 14 additions & 0 deletions example/select_image/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
contextual_menu:
dependency: "direct main"
description:
name: contextual_menu
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -156,6 +163,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
menu_base:
dependency: transitive
description:
name: menu_base
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
meta:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions example/select_image/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
path: ../../
file_picker: ^4.5.1
image: ^3.1.3
contextual_menu: ^0.1.1

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h"

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

void RegisterPlugins(flutter::PluginRegistry* registry) {
BetrayalPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BetrayalPlugin"));
ContextualMenuPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ContextualMenuPlugin"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
betrayal
contextual_menu
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 9704cf6

Please sign in to comment.