| Flutter macOS Embedder |

FlutterPluginRegistrarMacOS.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6
7 #import "FlutterBinaryMessenger.h"
8 #import "FlutterChannels.h"
9 #import "FlutterMacros.h"
10 #import "FlutterPlatformViews.h"
11 #import "FlutterPluginMacOS.h"
12 #import "FlutterTexture.h"
13
14 // TODO(stuartmorgan): Merge this file and FlutterPluginMacOS.h with the iOS FlutterPlugin.h,
15 // sharing all but the platform-specific methods.
16
17 /**
18 * The protocol for an object managing registration for a plugin. It provides access to application
19 * context, as allowing registering for callbacks for handling various conditions.
20 *
21 * Currently the macOS PluginRegistrar has very limited functionality, but is expected to expand
22 * over time to more closely match the functionality of FlutterPluginRegistrar.
23 */
24 FLUTTER_DARWIN_EXPORT
25 @protocol FlutterPluginRegistrar <NSObject>
26
27 /**
28 * The binary messenger used for creating channels to communicate with the Flutter engine.
29 */
30 @property(nonnull, readonly) id<FlutterBinaryMessenger> messenger;
31
32 /**
33 * Returns a `FlutterTextureRegistry` for registering textures
34 * provided by the plugin.
35 */
36 @property(nonnull, readonly) id<FlutterTextureRegistry> textures;
37
38 /**
39 * The view displaying Flutter content.
40 *
41 * This property is provided for backwards compatibility for apps
42 * that assume a single view. This will eventually be replaced by
43 * a multi-view API variant.
44 *
45 * This method may return |nil|, for instance in a headless environment.
46 */
47 @property(nullable, readonly) NSView* view;
48
49 /**
50 * Registers |delegate| to receive handleMethodCall:result: callbacks for the given |channel|.
51 */
52 - (void)addMethodCallDelegate:(nonnull id<FlutterPlugin>)delegate
53 channel:(nonnull FlutterMethodChannel*)channel;
54
55 /**
56 * Registers the plugin as a receiver of `NSApplicationDelegate` calls.
57 *
58 * @param delegate The receiving object, such as the plugin's main class.
59 */
60 - (void)addApplicationDelegate:(nonnull NSObject<FlutterAppLifecycleDelegate>*)delegate;
61
62 /**
63 * Registers a `FlutterPlatformViewFactory` for creation of platform views.
64 *
65 * Plugins expose `NSView` for embedding in Flutter apps by registering a view factory.
66 *
67 * @param factory The view factory that will be registered.
68 * @param factoryId A unique identifier for the factory, the Dart code of the Flutter app can use
69 * this identifier to request creation of a `NSView` by the registered factory.
70 */
71 - (void)registerViewFactory:(nonnull NSObject<FlutterPlatformViewFactory>*)factory
72 withId:(nonnull NSString*)factoryId;
73
74 /**
75 * Publishes a value for external use of the plugin.
76 *
77 * Plugins may publish a single value, such as an instance of the
78 * plugin's main class, for situations where external control or
79 * interaction is needed.
80 *
81 * The published value will be available from the `FlutterPluginRegistry`.
82 * Repeated calls overwrite any previous publication.
83 *
84 * @param value The value to be published.
85 */
86 - (void)publish:(nonnull NSObject*)value;
87
88 /**
89 * Returns the file name for the given asset.
90 * The returned file name can be used to access the asset in the application's main bundle.
91 *
92 * @param asset The name of the asset. The name can be hierarchical.
93 * @return the file name to be used for lookup in the main bundle.
94 */
95 - (nonnull NSString*)lookupKeyForAsset:(nonnull NSString*)asset;
96
97 /**
98 * Returns the file name for the given asset which originates from the specified package.
99 * The returned file name can be used to access the asset in the application's main bundle.
100 *
101 *
102 * @param asset The name of the asset. The name can be hierarchical.
103 * @param package The name of the package from which the asset originates.
104 * @return the file name to be used for lookup in the main bundle.
105 */
106 - (nonnull NSString*)lookupKeyForAsset:(nonnull NSString*)asset
107 fromPackage:(nonnull NSString*)package;
108
109 @end
110
111 /**
112 * A registry of Flutter macOS plugins.
113 *
114 * Plugins are identified by unique string keys, typically the name of the
115 * plugin's main class.
116 *
117 * Plugins typically need contextual information and the ability to register
118 * callbacks for various application events. To keep the API of the registry
119 * focused, these facilities are not provided directly by the registry, but by
120 * a `FlutterPluginRegistrar`, created by the registry in exchange for the unique
121 * key of the plugin.
122 *
123 * There is no implied connection between the registry and the registrar.
124 * Specifically, callbacks registered by the plugin via the registrar may be
125 * relayed directly to the underlying iOS application objects.
126 */
127 @protocol FlutterPluginRegistry <NSObject>
128
129 /**
130 * Returns a registrar for registering a plugin.
131 *
132 * @param pluginKey The unique key identifying the plugin.
133 */
134 - (nonnull id<FlutterPluginRegistrar>)registrarForPlugin:(nonnull NSString*)pluginKey;
135
136 /**
137 * Returns a value published by the specified plugin.
138 *
139 * @param pluginKey The unique key identifying the plugin.
140 * @return An object published by the plugin, if any. Will be `NSNull` if
141 * nothing has been published. Will be `nil` if the plugin has not been
142 * registered.
143 */
144 - (nullable NSObject*)valuePublishedByPlugin:(nonnull NSString*)pluginKey;
145
146 @end
FlutterPlatformViews.h
FlutterPlugin-p
Definition: FlutterPluginMacOS.h:26
FlutterMethodChannel
Definition: FlutterChannels.h:222
FlutterPluginMacOS.h
FlutterPluginRegistrar-p::textures
id< FlutterTextureRegistry > textures
Definition: FlutterPluginRegistrarMacOS.h:36
FlutterTexture.h
FlutterChannels.h
FlutterMacros.h
FlutterPluginRegistrar-p
Definition: FlutterPluginRegistrarMacOS.h:25
FlutterPluginRegistrar-p::messenger
id< FlutterBinaryMessenger > messenger
Definition: FlutterPluginRegistrarMacOS.h:30
FlutterAppLifecycleDelegate-p
Definition: FlutterAppLifecycleDelegate.h:21
FlutterBinaryMessenger.h
FlutterPlatformViewFactory-p
Definition: FlutterPlatformViews.h:13
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
FlutterPluginRegistrar-p::view
NSView * view
Definition: FlutterPluginRegistrarMacOS.h:47