| Flutter macOS Embedder |

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

`#import <FlutterViewController.h>`

Inheritance diagram for FlutterViewController:

## Instance Methods
(nonnull instancetype) | - initWithProject:
(nonnull instancetype) | - initWithNibName:bundle:
(nonnull instancetype) | - initWithCoder:
(nonnull instancetype) | - initWithEngine:nibName:bundle:
(BOOL) | - attached
(void) | - onPreEngineRestart
(nonnull NSString *) | - lookupKeyForAsset:
(nonnull NSString *) | - lookupKeyForAsset:fromPackage:
(void) | - onAccessibilityStatusChanged:
(std::shared_ptr< flutter::AccessibilityBridgeMac >) | - createAccessibilityBridgeWithEngine:
(nonnull FlutterView *) | - createFlutterViewWithMTLDevice:commandQueue:
Instance Methods inherited from <FlutterPluginRegistry>
(nonnull id< FlutterPluginRegistrar >) | - registrarForPlugin:
(nullable NSObject *) | - valuePublishedByPlugin:

## Properties
FlutterEngine * | engine
FlutterMouseTrackingMode | mouseTrackingMode
FlutterViewIdentifier | viewIdentifier
NSColor * | backgroundColor

## Detailed Description

Controls a view that displays Flutter content and manages input.

A FlutterViewController works with a FlutterEngine. Upon creation, the view controller is always added to an engine, either a given engine, or it implicitly creates an engine and add itself to that engine.

The FlutterEngine assigns each view controller attached to it a unique ID. Each view controller corresponds to a view, and the ID is used by the framework to specify which view to operate.

A FlutterViewController can also be unattached to an engine after it is manually unset from the engine, or transiently during the initialization process. An unattached view controller is invalid. Whether the view controller is attached can be queried using attached (FlutterViewController).

The FlutterViewController strongly references the FlutterEngine, while the engine weakly the view controller. When a FlutterViewController is deallocated, it automatically removes itself from its attached engine. When a FlutterEngine has no FlutterViewControllers attached, it might shut down itself or not depending on its configuration.

Definition at line 73 of file FlutterViewController.h.

## Method Documentation

## ◆ attached

- (BOOL) attached |  |  |

Return YES if the view controller is attached to an engine.

Definition at line 319 of file FlutterViewController.mm.

488 {
489 return _engine != nil;
490 }

References engine, and viewIdentifier.

## ◆ createAccessibilityBridgeWithEngine:

- (shared_ptr<)flutter: |  | (nonnull FlutterEngine *) | engine |

Reimplemented in AccessibilityBridgeTestViewController.

Provided by category FlutterViewController(TestMethods).

## ◆ createFlutterViewWithMTLDevice:commandQueue:

- (nonnull FlutterView*) createFlutterViewWithMTLDevice: |  | (nonnull id< MTLDevice >) | device
commandQueue: |  | (nonnull id< MTLCommandQueue >) | commandQueue

Provided by category FlutterViewController(TestMethods).

## ◆ initWithCoder:

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

## ◆ initWithEngine:nibName:bundle:

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

Initializes this FlutterViewController with an existing `FlutterEngine`.

The initialized view controller will add itself to the engine as part of this process.

This initializer is suitable for both the first Flutter view controller and the following ones of the app.

Parameters

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

Definition at line 319 of file FlutterViewController.mm.

365 :(nonnull FlutterEngine*)engine
366 nibName:(nullable NSString*)nibName
367 bundle:(nullable NSBundle*)nibBundle {
368 NSAssert(engine != nil, @"Engine is required");
369
370 self = [super initWithNibName:nibName bundle:nibBundle];
371 if (self) {
372 CommonInit(self, engine);
373 }
374
375 return self;
376 }
FlutterEngine
Definition: FlutterEngine.h:32
FlutterViewController::engine
FlutterEngine * engine
Definition: FlutterViewController.h:78

## ◆ initWithNibName:bundle:

- (nonnull instancetype) initWithNibName: |  | (nullable NSString *) | nibNameOrNil
bundle: |  | (nullable NSBundle *) | NS_DESIGNATED_INITIALIZER

## ◆ initWithProject:

- (instancetype) initWithProject: |  | (nullable FlutterDartProject*) | NS_DESIGNATED_INITIALIZER |

Initializes a controller that will run the given project.

In this initializer, this controller creates an engine, and is attached to that engine as the default controller. In this way, this controller can not be set to other engines. This initializer is suitable for the first Flutter view controller of the app. To use the controller with an existing engine, use initWithEngine:nibName:bundle: instead.

Parameters

  project | The project to run in this view controller. If nil, a default `FlutterDartProject` will be used.

Definition at line 319 of file FlutterViewController.mm.

356 :(nullable FlutterDartProject*)project {
357 self = [super initWithNibName:nil bundle:nil];
358 NSAssert(self, @"Super init cannot be nil");
359
360 _project = project;
361 CommonInit(self, nil);
362 return self;
363 }
_project
FlutterDartProject * _project
Definition: FlutterEngine.mm:419
FlutterDartProject
Definition: FlutterDartProject.mm:24

## ◆ lookupKeyForAsset:

- (nonnull NSString*) lookupKeyForAsset: |  | (nonnull 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.

## ◆ lookupKeyForAsset:fromPackage:

- (nonnull NSString*) lookupKeyForAsset: |  | (nonnull NSString *) | asset
fromPackage: |  | (nonnull 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.

## ◆ onAccessibilityStatusChanged:

- (void) onAccessibilityStatusChanged: |  | (BOOL) | enabled |

Provided by category FlutterViewController(TestMethods).

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

## ◆ onPreEngineRestart

- (void) onPreEngineRestart |  |  |

Invoked by the engine right before the engine is restarted.

This should reset states to as if the application has just started. It usually indicates a hot restart (Shift-R in Flutter CLI.)

Definition at line 319 of file FlutterViewController.mm.

453 {
454 }

## Property Documentation

## ◆ backgroundColor

- (NSColor*) backgroundColor
| read write nonatomic copy

The contentView (FlutterView)'s background color is set to black during its instantiation.

The containing layer's color can be set to the NSColor provided to this method.

For example, the background may be set after the FlutterViewController is instantiated in MainFlutterWindow.swift in the Flutter project.

import Cocoa
import FlutterMacOS
class MainFlutterWindow: NSWindow {
override func awakeFromNib() {
let flutterViewController = FlutterViewController()
// The background color of the window and `FlutterViewController`
// are retained separately.
//
// In this example, both the MainFlutterWindow and FlutterViewController's
// FlutterView's backgroundColor are set to clear to achieve a fully
// transparent effect.
//
// If the window's background color is not set, it will use the system
// default.
//
// If the `FlutterView`'s color is not set via `FlutterViewController.setBackgroundColor`
// it's default will be black.
self.backgroundColor = NSColor.clear
flutterViewController.backgroundColor = NSColor.clear
let windowFrame = self.frame
self.contentViewController = flutterViewController
self.setFrame(windowFrame, display: true)
RegisterGeneratedPlugins(registry: flutterViewController)
super.awakeFromNib()
}
}

Definition at line 210 of file FlutterViewController.h.

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

## ◆ engine

- (FlutterEngine*) engine
| read nonatomic assign

The Flutter engine associated with this view controller.

Definition at line 78 of file FlutterViewController.h.

Referenced by attached, flutter::testing::TEST(), and flutter::testing::TEST_F().

## ◆ mouseTrackingMode

- (FlutterMouseTrackingMode) mouseTrackingMode
| read write nonatomic assign

The style of mouse tracking to use for the view. Defaults to FlutterMouseTrackingModeInKeyWindow.

Definition at line 84 of file FlutterViewController.h.

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

## ◆ viewIdentifier

- (FlutterViewIdentifier) viewIdentifier
| read nonatomic assign

The identifier for this view controller, if it is attached.

The identifier is assigned when the view controller is attached to a `FlutterEngine`.

If the view controller is detached (see `FlutterViewController#attached`), reading this property throws an assertion.

Definition at line 130 of file FlutterViewController.h.

Referenced by attached, and flutter::testing::TEST_F().

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

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