FlutterViewController
@interface FlutterViewController
: UIViewController <FlutterTextureRegistry, FlutterPluginRegistry>
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.cn/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.
-
Initializes this FlutterViewController with the specified
FlutterEngine
.The initialized viewcontroller will attach itself to the engine as part of this process.
Declaration
Objective-C
- (nonnull instancetype)initWithEngine:(nonnull FlutterEngine *)engine nibName:(nullable NSString *)nibName bundle:(nullable NSBundle *)nibBundle;
Parameters
engine
The
FlutterEngine
instance to attach to. Cannot be nil.nibName
The NIB name to initialize this UIViewController with.
nibBundle
The NIB bundle.
-
Initializes a new FlutterViewController and
FlutterEngine
with the specifiedFlutterDartProject
.This will implicitly create a new
FlutterEngine
which is retrievable via theengine
property after initialization.Declaration
Objective-C
- (nonnull instancetype)initWithProject:(nullable FlutterDartProject *)project nibName:(nullable NSString *)nibName bundle:(nullable NSBundle *)nibBundle;
Parameters
project
The
FlutterDartProject
to initialize theFlutterEngine
with.nibName
The NIB name to initialize this UIViewController with.
nibBundle
The NIB bundle.
-
Initializes a new FlutterViewController and
FlutterEngine
with the specifiedFlutterDartProject
andinitialRoute
.This will implicitly create a new
FlutterEngine
which is retrievable via theengine
property after initialization.Declaration
Objective-C
- (nonnull instancetype)initWithProject:(nullable FlutterDartProject *)project initialRoute:(nullable NSString *)initialRoute nibName:(nullable NSString *)nibName bundle:(nullable NSBundle *)nibBundle;
Parameters
project
The
FlutterDartProject
to initialize theFlutterEngine
with.initialRoute
The initial
Navigator
route to load.nibName
The NIB name to initialize this UIViewController with.
nibBundle
The NIB bundle.
-
Initializer that is called from loading a FlutterViewController from a XIB.
See also: https://developer.apple.com/documentation/foundation/nscoding/1416145-initwithcoder?language=objc
Declaration
Objective-C
- (nonnull instancetype)initWithCoder:(nonnull NSCoder *)aDecoder;
-
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.Declaration
Objective-C
- (void)setFlutterViewDidRenderCallback:(nonnull void (^)(void))callback;
-
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.
Declaration
Objective-C
- (nonnull NSString *)lookupKeyForAsset:(nonnull NSString *)asset;
Parameters
asset
The name of the asset. The name can be hierarchical.
Return Value
The file name to be used for lookup in the main bundle.
-
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.
Declaration
Objective-C
- (nonnull NSString *)lookupKeyForAsset:(nonnull NSString *)asset fromPackage:(nonnull NSString *)package;
Parameters
asset
The name of the asset. The name can be hierarchical.
package
The name of the package from which the asset originates.
Return Value
The file name to be used for lookup in the main bundle.
-
Deprecated
Use FlutterViewController initializer to specify initial route
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 usinginitWithEngine
if theFlutterEngine
has already been run.Setting this after the Flutter started running has no effect. See
pushRoute
andpopRoute
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 usinginitWithEngine
, the initial route should be set on the engine’s initializer.Declaration
Objective-C
- (void)setInitialRoute:(nonnull NSString *)route;
Parameters
route
The name of the first route to show.
-
Instructs the Flutter Navigator (if any) to go back.
Declaration
Objective-C
- (void)popRoute;
-
Instructs the Flutter Navigator (if any) to push a route on to the navigation stack.
Declaration
Objective-C
- (void)pushRoute:(nonnull NSString *)route;
Parameters
route
The name of the route to push to the navigation stack.
-
The
FlutterPluginRegistry
used by this FlutterViewController.Declaration
Objective-C
- (nonnull id<FlutterPluginRegistry>)pluginRegistry;
-
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.
Declaration
Objective-C
@property (nonatomic, readonly, getter=isDisplayingFlutterUI) BOOL displayingFlutterUI;
-
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 theFlutter 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.
Declaration
Objective-C
@property (nonatomic, strong, readwrite) UIView *_Nonnull splashScreenView;
-
Attempts to set the
splashScreenView
property from theUILaunchStoryboardName
from the main bundle’sInfo.plist
file. This method will not change the value ofsplashScreenView
if it cannot find a default one from a storyboard or nib.Declaration
Objective-C
- (BOOL)loadDefaultSplashScreenView;
Return Value
YES
if successful,NO
otherwise. -
Controls whether the created view will be opaque or not.
Default is
YES
. Note that setting this toNO
may negatively impact performance when using hardware acceleration, and toggling this will trigger a re-layout of the view.Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite, getter=isViewOpaque) BOOL viewOpaque;
-
The
FlutterEngine
instance for this view controller. This could be the engine thisFlutterViewController
is initialized with or a newFlutterEngine
implicitly created if no engine was supplied during initialization.Declaration
Objective-C
@property (nonatomic, weak, readonly) FlutterEngine *_Nullable engine;
-
The
FlutterBinaryMessenger
associated with this FlutterViewController (used for communicating with channels).This is just a convenient way to get the |FlutterEngine|‘s binary messenger.
Declaration
Objective-C
@property (nonatomic, readonly) NSObject<FlutterBinaryMessenger> *_Nonnull binaryMessenger;
-
If the
FlutterViewController
creates aFlutterEngine
, this property determines if thatFlutterEngine
hasallowHeadlessExecution
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:]
Declaration
Objective-C
@property (nonatomic, readonly) BOOL engineAllowHeadlessExecution;