| Flutter macOS Embedder |

FlutterEngine.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_FLUTTERENGINE_H_
6 #define FLUTTER_FLUTTERENGINE_H_
7
8 #import <Foundation/Foundation.h>
9
10 #include <stdint.h>
11
12 #import "FlutterAppLifecycleDelegate.h"
13 #import "FlutterBinaryMessenger.h"
14 #import "FlutterDartProject.h"
15 #import "FlutterMacros.h"
16 #import "FlutterPluginRegistrarMacOS.h"
17 #import "FlutterTexture.h"
18
19 // TODO(stuartmorgan): Merge this file with the iOS FlutterEngine.h.
20
21 @class FlutterViewController;
22
23 /**
24 * Coordinates a single instance of execution of a Flutter engine.
25 *
26 * A FlutterEngine can only be attached with one controller from the native
27 * code.
28 */
29 FLUTTER_DARWIN_EXPORT
30 @interface FlutterEngine
31 : NSObject <FlutterTextureRegistry, FlutterPluginRegistry, FlutterAppLifecycleDelegate>
32
33 /**
34 * Initializes an engine with the given project.
35 *
36 * @param labelPrefix Currently unused; in the future, may be used for labelling threads
37 * as with the iOS FlutterEngine.
38 * @param project The project configuration. If nil, a default FlutterDartProject will be used.
39 */
40 - (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix
41 project:(nullable FlutterDartProject*)project;
42
43 /**
44 * Initializes an engine that can run headlessly with the given project.
45 *
46 * @param labelPrefix Currently unused; in the future, may be used for labelling threads
47 * as with the iOS FlutterEngine.
48 * @param project The project configuration. If nil, a default FlutterDartProject will be used.
49 */
50 - (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix
51 project:(nullable FlutterDartProject*)project
52 allowHeadlessExecution:(BOOL)allowHeadlessExecution NS_DESIGNATED_INITIALIZER;
53
54 - (nonnull instancetype)init NS_UNAVAILABLE;
55
56 /**
57 * Runs a Dart program on an Isolate from the main Dart library (i.e. the library that
58 * contains `main()`).
59 *
60 * The first call to this method will create a new Isolate. Subsequent calls will return
61 * immediately.
62 *
63 * @param entrypoint The name of a top-level function from the same Dart
64 * library that contains the app's main() function. If this is nil, it will
65 * default to `main()`. If it is not the app's main() function, that function
66 * must be decorated with `@pragma(vm:entry-point)` to ensure the method is not
67 * tree-shaken by the Dart compiler.
68 * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
69 */
70 - (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint;
71
72 /**
73 * The `FlutterViewController` of this engine, if any.
74 *
75 * This view is used by legacy APIs that assume a single view.
76 *
77 * Setting this field from nil to a non-nil view controller also updates
78 * the view controller's engine and ID.
79 *
80 * Setting this field from non-nil to nil will terminate the engine if
81 * allowHeadlessExecution is NO.
82 *
83 * Setting this field from non-nil to a different non-nil FlutterViewController
84 * is prohibited and will throw an assertion error.
85 */
86 @property(nonatomic, nullable, weak) FlutterViewController* viewController;
87
88 /**
89 * The `FlutterBinaryMessenger` for communicating with this engine.
90 */
91 @property(nonatomic, nonnull, readonly) id<FlutterBinaryMessenger> binaryMessenger;
92
93 /**
94 * Shuts the Flutter engine if it is running. The FlutterEngine instance must always be shutdown
95 * before it may be collected. Not shutting down the FlutterEngine instance before releasing it will
96 * result in the leak of that engine instance.
97 */
98 - (void)shutDownEngine;
99
100 @end
101
102 #endif // FLUTTER_FLUTTERENGINE_H_
FlutterEngine
Definition: FlutterEngine.h:30
FlutterViewController
Definition: FlutterViewController.h:62
FlutterTexture.h
FlutterEngine::viewController
FlutterViewController * viewController
Definition: FlutterEngine.h:86
FlutterMacros.h
-[FlutterEngine NS_UNAVAILABLE]
nonnull instancetype NS_UNAVAILABLE()
FlutterEngine::binaryMessenger
id< FlutterBinaryMessenger > binaryMessenger
Definition: FlutterEngine.h:91
FlutterPluginRegistrarMacOS.h
FlutterBinaryMessenger.h
FlutterDartProject.h
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
-[FlutterEngine shutDownEngine]
void shutDownEngine()
Definition: FlutterEngine.mm:1016
FlutterDartProject
Definition: FlutterDartProject.mm:24
FlutterAppLifecycleDelegate.h