Flutter macOS Embedder
FlutterEngine Class Reference

#import <FlutterEngine.h>

Inheritance diagram for FlutterEngine:
MockableFlutterEngine

Instance Methods

(nonnull instancetype) - initWithName:project:
 
(nonnull instancetype) - initWithName:project:allowHeadlessExecution:
 
(nonnull instancetype) - NS_UNAVAILABLE
 
(BOOL) - runWithEntrypoint:
 
(void) - shutDownEngine
 
(nonnull FlutterThreadSynchronizer *) - testThreadSynchronizer
 

Protected Attributes

 __pad0__: NSObject <FlutterTextureRegistry
 
 FlutterPluginRegistry
 

Properties

FlutterViewControllerviewController
 
id< FlutterBinaryMessengerbinaryMessenger
 

Detailed Description

Coordinates a single instance of execution of a Flutter engine.

A FlutterEngine can only be attached with one controller from the native code.

Definition at line 30 of file FlutterEngine.h.

Method Documentation

◆ initWithName:project:

- (nonnull instancetype) initWithName: (nonnull NSString *)  labelPrefix
project: (nullable FlutterDartProject *)  project 

Initializes an engine with the given project.

Parameters
labelPrefixCurrently unused; in the future, may be used for labelling threads as with the iOS FlutterEngine.
projectThe project configuration. If nil, a default FlutterDartProject will be used.

◆ initWithName:project:allowHeadlessExecution:

- (nonnull instancetype) initWithName: (nonnull NSString *)  labelPrefix
project: (nullable FlutterDartProject *)  project
allowHeadlessExecution: (BOOL)  NS_DESIGNATED_INITIALIZER 

Initializes an engine that can run headlessly with the given project.

Parameters
labelPrefixCurrently unused; in the future, may be used for labelling threads as with the iOS FlutterEngine.
projectThe project configuration. If nil, a default FlutterDartProject will be used.

◆ NS_UNAVAILABLE

- (nonnull instancetype) NS_UNAVAILABLE

◆ runWithEntrypoint:

- (BOOL) runWithEntrypoint: (nullable NSString *)  entrypoint

Runs a Dart program on an Isolate from the main Dart library (i.e. the library that contains main()).

The first call to this method will create a new Isolate. Subsequent calls will return immediately.

Parameters
entrypointThe name of a top-level function from the same Dart library that contains the app's main() function. If this is nil, it will default to main(). If it is not the app's main() function, that function must be decorated with @pragma(vm:entry-point) to ensure the method is not tree-shaken by the Dart compiler.
Returns
YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.

◆ shutDownEngine

- (void) shutDownEngine

Shuts the Flutter engine if it is running. The FlutterEngine instance must always be shutdown before it may be collected. Not shutting down the FlutterEngine instance before releasing it will result in the leak of that engine instance.

Note: Called from dealloc. Should not use accessors or other methods.

Definition at line 1130 of file FlutterEngine.mm.

1130  {
1131  if (_engine == nullptr) {
1132  return;
1133  }
1134 
1135  [_threadSynchronizer shutdown];
1136  _threadSynchronizer = nil;
1137 
1138  FlutterEngineResult result = _embedderAPI.Deinitialize(_engine);
1139  if (result != kSuccess) {
1140  NSLog(@"Could not de-initialize the Flutter engine: error %d", result);
1141  }
1142 
1143  // Balancing release for the retain in the task runner dispatch table.
1144  CFRelease((CFTypeRef)self);
1145 
1146  result = _embedderAPI.Shutdown(_engine);
1147  if (result != kSuccess) {
1148  NSLog(@"Failed to shut down Flutter engine: error %d", result);
1149  }
1150  _engine = nullptr;
1151 }

References _threadSynchronizer.

Referenced by flutter::testing::FlutterEngineTest::ShutDownEngine(), flutter::testing::FlutterEngineTest::TearDown(), and flutter::testing::TEST_F().

◆ testThreadSynchronizer

- (nonnull FlutterThreadSynchronizer*) testThreadSynchronizer

Provided by category FlutterEngine(Tests).

Member Data Documentation

◆ __pad0__

- __pad0__
protected

Definition at line 31 of file FlutterEngine.h.

◆ FlutterPluginRegistry

- FlutterPluginRegistry
protected

Definition at line 31 of file FlutterEngine.h.

Property Documentation

◆ binaryMessenger

- (id< FlutterBinaryMessenger >) binaryMessenger
readnonatomicassign

The FlutterBinaryMessenger for communicating with this engine.

Definition at line 91 of file FlutterEngine.h.

Referenced by flutter::testing::TEST_F().

◆ viewController

- (FlutterViewController *) viewController
readwritenonatomicweak

The FlutterViewController of this engine, if any.

This view is used by legacy APIs that assume a single view.

Setting this field from nil to a non-nil view controller also updates the view controller's engine and ID.

Setting this field from non-nil to nil will terminate the engine if allowHeadlessExecution is NO.

Setting this field from non-nil to a different non-nil FlutterViewController is prohibited and will throw an assertion error.

Definition at line 86 of file FlutterEngine.h.

Referenced by flutter::testing::TEST_F().


The documentation for this class was generated from the following files:
_threadSynchronizer
FlutterThreadSynchronizer * _threadSynchronizer
Definition: FlutterEngine.mm:458