| Flutter iOS Embedder |

Instance Methods | Class Methods | Properties | List of all members
FlutterViewController Class Reference

`#import <FlutterViewController.h>`

Inheritance diagram for FlutterViewController:

## Instance Methods
(instancetype) | - initWithEngine:nibName:bundle:
(instancetype) | - initWithProject:nibName:bundle:
(instancetype) | - initWithProject:initialRoute:nibName:bundle:
(instancetype) | - initWithCoder:
(void) | - setFlutterViewDidRenderCallback:
(NSString *) | - lookupKeyForAsset:
(NSString *) | - lookupKeyForAsset:fromPackage:
(void) | - setInitialRoute:
(void) | - popRoute
(void) | - pushRoute:
(id< FlutterPluginRegistry >) | - pluginRegistry
(BOOL) | - loadDefaultSplashScreenView
Instance Methods inherited from <FlutterTextureRegistry>
(int64_t) | - registerTexture:
(void) | - textureFrameAvailable:
(void) | - unregisterTexture:
Instance Methods inherited from <FlutterPluginRegistry>
(nullable NSObject< FlutterPluginRegistrar > *) | - registrarForPlugin:
(BOOL) | - hasPlugin:
(nullable NSObject *) | - valuePublishedByPlugin:

## Class Methods
(BOOL) | + isUIAccessibilityIsVoiceOverRunning

## Properties
BOOL | displayingFlutterUI
UIView * | splashScreenView
BOOL | viewOpaque
FlutterEngine * | engine
NSObject< FlutterBinaryMessenger > * | binaryMessenger
BOOL | engineAllowHeadlessExecution

## Detailed Description

A `UIViewController` implementation for Flutter views.

Dart execution, channel communication, texture registration, and plugin registration are all handled by `FlutterEngine`. Calls on this class to those members all proxy through to the `FlutterEngine` attached FlutterViewController.

A FlutterViewController can be initialized either with an already-running `FlutterEngine` via the `initWithEngine:` initializer, or it can be initialized with a `FlutterDartProject` that will be used to implicitly spin up a new `FlutterEngine`. Creating a `FlutterEngine` before showing a FlutterViewController can be used to pre-initialize the Dart VM and to prepare the isolate in order to reduce the latency to the first rendered frame. See https://flutter.dev/docs/development/add-to-app/performance for more details on loading latency.

Holding a `FlutterEngine` independently of FlutterViewControllers can also be used to not to lose Dart-related state and asynchronous tasks when navigating back and forth between a FlutterViewController and other `UIViewController`s.

Definition at line 56 of file FlutterViewController.h.

## Method Documentation

## ◆ initWithCoder:

- (instancetype) initWithCoder: |  | (NSCoder*) | NS_DESIGNATED_INITIALIZER |

Initializer that is called from loading a FlutterViewController from a XIB.

See also: https://developer.apple.com/documentation/foundation/nscoding/1416145-initwithcoder?language=objc

Definition at line 218 of file FlutterViewController.mm.

218 :(NSCoder*)aDecoder {
219 self = [super initWithCoder:aDecoder];
220 return self;
221 }

## ◆ initWithEngine:nibName:bundle:

- (instancetype) initWithEngine: |  | (FlutterEngine*) | engine
nibName: |  | (nullable NSString*) | nibName
bundle: |  | (nullable NSBundle*) | NS_DESIGNATED_INITIALIZER

Initializes this FlutterViewController with the specified `FlutterEngine`.

The initialized viewcontroller will attach itself to the engine as part of this process.

Parameters

  engine | The `FlutterEngine` instance to attach to. Cannot be nil.
  nibName | The NIB name to initialize this UIViewController with.
  nibBundle | The NIB bundle.

Definition at line 161 of file FlutterViewController.mm.

161 :(FlutterEngine*)engine
162 nibName:(nullable NSString*)nibName
163 bundle:(nullable NSBundle*)nibBundle {
164 NSAssert(engine != nil, @"Engine is required");
165 self = [super initWithNibName:nibName bundle:nibBundle];
166 if (self) {
167 _viewOpaque = YES;
168 if (engine.viewController) {
169 FML_LOG(ERROR) << "The supplied FlutterEngine " << [[engine description] UTF8String]
170 << " is already used with FlutterViewController instance "
171 << [[engine.viewController description] UTF8String]
172 << ". One instance of the FlutterEngine can only be attached to one "
173 "FlutterViewController at a time. Set FlutterEngine.viewController "
174 "to nil before attaching it to another FlutterViewController.";
175 }
176 _engine.reset([engine retain]);
177 _engineNeedsLaunch = NO;
178 _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine
179 opaque:self.isViewOpaque
180 enableWideGamut:engine.project.isWideGamutEnabled]);
181 _weakFactory = std::make_unique<fml::WeakNSObjectFactory<FlutterViewController>>(self);
182 _ongoingTouches.reset([[NSMutableSet alloc] init]);
183
184 [self performCommonViewControllerInitialization];
185 [engine setViewController:self];
186 }
187
188 return self;
189 }

References _engine, _engineNeedsLaunch, _flutterView, _ongoingTouches, _viewOpaque, _weakFactory, and engine.

## ◆ initWithProject:initialRoute:nibName:bundle:

- (instancetype) initWithProject: |  | (nullable FlutterDartProject *) | project
initialRoute: |  | (nullable NSString *) | initialRoute
nibName: |  | (nullable NSString *) | nibName
bundle: |  | (nullable NSBundle *) | NS_DESIGNATED_INITIALIZER

Initializes a new FlutterViewController and `FlutterEngine` with the specified `FlutterDartProject` and `initialRoute`.

This will implicitly create a new `FlutterEngine` which is retrievable via the `engine` property after initialization.

Parameters

  project | The `FlutterDartProject` to initialize the `FlutterEngine` with.
  initialRoute | The initial `Navigator` route to load.
  nibName | The NIB name to initialize this UIViewController with.
  nibBundle | The NIB bundle.

## ◆ initWithProject:nibName:bundle:

- (instancetype) initWithProject: |  | (nullable FlutterDartProject *) | project
nibName: |  | (nullable NSString *) | nibName
bundle: |  | (nullable NSBundle *) | NS_DESIGNATED_INITIALIZER

Initializes a new FlutterViewController and `FlutterEngine` with the specified `FlutterDartProject`.

This will implicitly create a new `FlutterEngine` which is retrievable via the `engine` property after initialization.

Parameters

  project | The `FlutterDartProject` to initialize the `FlutterEngine` with.
  nibName | The NIB name to initialize this UIViewController with.
  nibBundle | The NIB bundle.

## ◆ isUIAccessibilityIsVoiceOverRunning

+ (BOOL) isUIAccessibilityIsVoiceOverRunning |  |  |

A wrapper around UIAccessibilityIsVoiceOverRunning().

As a C function, UIAccessibilityIsVoiceOverRunning() cannot be mocked in testing. Mock this class method to testing features depends on UIAccessibilityIsVoiceOverRunning().

Definition at line 2361 of file FlutterViewController.mm.

2361 {
2362 return UIAccessibilityIsVoiceOverRunning();
2363 }

## ◆ loadDefaultSplashScreenView

- (BOOL) loadDefaultSplashScreenView |  |  |

Attempts to set the `splashScreenView` property from the `UILaunchStoryboardName` from the main bundle's `Info.plist` file. This method will not change the value of `splashScreenView` if it cannot find a default one from a storyboard or nib.

Returns
  `YES` if successful, `NO` otherwise.

Definition at line 673 of file FlutterViewController.mm.

673 {
674 NSString* launchscreenName =
675 [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchStoryboardName"];
676 if (launchscreenName == nil) {
677 return NO;
678 }
679 UIView* splashView = [self splashScreenFromStoryboard:launchscreenName];
680 if (!splashView) {
681 splashView = [self splashScreenFromXib:launchscreenName];
682 }
683 if (!splashView) {
684 return NO;
685 }
686 self.splashScreenView = splashView;
687 return YES;
688 }

## ◆ lookupKeyForAsset:

- (NSString *) lookupKeyForAsset: |  | (NSString*) | asset |

Returns the file name for the given asset. The returned file name can be used to access the asset in the application's main bundle.

Parameters

  asset | The name of the asset. The name can be hierarchical.

Returns
  The file name to be used for lookup in the main bundle.

Definition at line 2349 of file FlutterViewController.mm.

2349 :(NSString*)asset {
2350 return [FlutterDartProject lookupKeyForAsset:asset];
2351 }

References FlutterDartProject::lookupKeyForAsset:.

## ◆ lookupKeyForAsset:fromPackage:

- (NSString *) lookupKeyForAsset: |  | (NSString*) | asset
fromPackage: |  | (NSString*) | package

Returns the file name for the given asset which originates from the specified package. The returned file name can be used to access the asset in the application's main bundle.

Parameters

  asset | The name of the asset. The name can be hierarchical.
  package | The name of the package from which the asset originates.

Returns
  The file name to be used for lookup in the main bundle.

Definition at line 2353 of file FlutterViewController.mm.

2353 :(NSString*)asset fromPackage:(NSString*)package {
2354 return [FlutterDartProject lookupKeyForAsset:asset fromPackage:package];
2355 }

References FlutterDartProject::lookupKeyForAsset:fromPackage:.

## ◆ pluginRegistry

- (id< FlutterPluginRegistry >) pluginRegistry |  |  |

The `FlutterPluginRegistry` used by this FlutterViewController.

Definition at line 2357 of file FlutterViewController.mm.

2357 {
2358 return _engine;
2359 }

References _engine.

## ◆ popRoute

- (void) popRoute |  |  |

Instructs the Flutter Navigator (if any) to go back.

Definition at line 453 of file FlutterViewController.mm.

453 {
454 [[_engine.get() navigationChannel] invokeMethod:@"popRoute" arguments:nil];
455 }

## ◆ pushRoute:

- (void) pushRoute: |  | (NSString*) | route |

Instructs the Flutter Navigator (if any) to push a route on to the navigation stack.

Parameters

  route | The name of the route to push to the navigation stack.

Definition at line 457 of file FlutterViewController.mm.

457 :(NSString*)route {
458 [[_engine.get() navigationChannel] invokeMethod:@"pushRoute" arguments:route];
459 }

## ◆ setFlutterViewDidRenderCallback:

- (void) setFlutterViewDidRenderCallback: |  | (void(^)(void)) | callback |

Registers a callback that will be invoked when the Flutter view has been rendered. The callback will be fired only once.

Replaces an existing callback. Use a `nil` callback to unregister the existing one.

Definition at line 732 of file FlutterViewController.mm.

732 :(void (^)(void))callback {
733 _flutterViewRenderedCallback.reset(callback, fml::scoped_policy::OwnershipPolicy::kRetain);
734 }

References _flutterViewRenderedCallback.

## ◆ setInitialRoute:

- (void) setInitialRoute: |  | ("Use FlutterViewController initializer to specify initial route") | FLUTTER_DEPRECATED |

Deprecated API to set initial route.

Attempts to set the first route that the Flutter app shows if the Flutter runtime hasn't yet started. The default is "/".

This method must be called immediately after `initWithProject` and has no effect when using `initWithEngine` if the `FlutterEngine` has already been run.

Setting this after the Flutter started running has no effect. See `pushRoute` and `popRoute` to change the route after Flutter started running.

This is deprecated because it needs to be called at the time of initialization and thus should just be in the `initWithProject` initializer. If using `initWithEngine`, the initial route should be set on the engine's initializer.

Parameters

  route | The name of the first route to show.

## Property Documentation

## ◆ binaryMessenger

- (NSObject< FlutterBinaryMessenger > *) binaryMessenger
| read nonatomic assign

The `FlutterBinaryMessenger` associated with this FlutterViewController (used for communicating with channels).

This is just a convenient way to get the |FlutterEngine|'s binary messenger.

Definition at line 243 of file FlutterViewController.h.

## ◆ displayingFlutterUI

- (BOOL) displayingFlutterUI
| read nonatomic assign

True if at least one frame has rendered and the ViewController has appeared.

This property is reset to false when the ViewController disappears. It is guaranteed to only alternate between true and false for observers.

Definition at line 197 of file FlutterViewController.h.

## ◆ engine

- (FlutterEngine *) engine
| read nonatomic weak

The `FlutterEngine` instance for this view controller. This could be the engine this `FlutterViewController` is initialized with or a new `FlutterEngine` implicitly created if no engine was supplied during initialization.

Definition at line 235 of file FlutterViewController.h.

## ◆ engineAllowHeadlessExecution

- (BOOL) engineAllowHeadlessExecution
| read nonatomic assign

If the `FlutterViewController` creates a `FlutterEngine`, this property determines if that `FlutterEngine` has `allowHeadlessExecution` set.

The intention is that this is used with the XIB. Otherwise, a `FlutterEngine` can just be sent to the init methods.

See also: `-[FlutterEngine initWithName:project:allowHeadlessExecution:]`

Definition at line 254 of file FlutterViewController.h.

## ◆ splashScreenView

- (UIView *) splashScreenView
| read write nonatomic strong

Specifies the view to use as a splash screen. Flutter's rendering is asynchronous, so the first frame rendered by the Flutter application might not immediately appear when the Flutter view is initially placed in the view hierarchy. The splash screen view will be used as a replacement until the first frame is rendered.

The view used should be appropriate for multiple sizes; an autoresizing mask to have a flexible width and height will be applied automatically.

Set to nil to remove the splash screen view.

Definition at line 210 of file FlutterViewController.h.

## ◆ viewOpaque

- (BOOL) viewOpaque
| read write nonatomic assign

Controls whether the created view will be opaque or not.

Default is `YES`. Note that setting this to `NO` may negatively impact performance when using hardware acceleration, and toggling this will trigger a re-layout of the view.

Definition at line 228 of file FlutterViewController.h.

The documentation for this class was generated from the following files:

- shell/platform/darwin/ios/framework/Headers/FlutterViewController.h
- shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

_flutterViewRenderedCallback
fml::ScopedBlock< void(^)(void)> _flutterViewRenderedCallback
Definition: FlutterViewController.mm:128
FlutterEngine
Definition: FlutterEngine.h:61
FlutterViewController::engine
FlutterEngine * engine
Definition: FlutterViewController.h:235
_engine
fml::scoped_nsobject< FlutterEngine > _engine
Definition: FlutterViewController.mm:120
_viewOpaque
BOOL _viewOpaque
Definition: FlutterViewController.mm:133
_flutterView
fml::scoped_nsobject< FlutterView > _flutterView
Definition: FlutterViewController.mm:126
+[FlutterDartProject lookupKeyForAsset:]
NSString * lookupKeyForAsset:(NSString *asset)
Definition: FlutterDartProject.mm:391
FlutterEngine::viewController
FlutterViewController * viewController
Definition: FlutterEngine.h:327
_engineNeedsLaunch
BOOL _engineNeedsLaunch
Definition: FlutterViewController.mm:134
_ongoingTouches
fml::scoped_nsobject< NSMutableSet< NSNumber * > > _ongoingTouches
Definition: FlutterViewController.mm:135
_weakFactory
std::unique_ptr< fml::WeakPtrFactory< FlutterDartVMServicePublisher > > _weakFactory
Definition: FlutterDartVMServicePublisher.mm:160
FlutterView
Definition: FlutterView.h:39
FlutterDartProject
Definition: FlutterDartProject.mm:264