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