Annotate nullability on FlutterEngine to make swift writing more ergonomic (flutter/engine#11808)
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
@class FlutterViewController;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* The FlutterEngine class coordinates a single instance of execution for a
|
||||
* `FlutterDartProject`. It may have zero or one `FlutterViewController` at a
|
||||
@@ -56,9 +58,9 @@ FLUTTER_EXPORT
|
||||
* @param labelPrefix The label prefix used to identify threads for this instance. Should
|
||||
* be unique across FlutterEngine instances, and is used in instrumentation to label
|
||||
* the threads used by this FlutterEngine.
|
||||
* @param projectOrNil The `FlutterDartProject` to run.
|
||||
* @param project The `FlutterDartProject` to run.
|
||||
*/
|
||||
- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)projectOrNil;
|
||||
- (instancetype)initWithName:(NSString*)labelPrefix project:(nullable FlutterDartProject*)project;
|
||||
|
||||
/**
|
||||
* Initialize this FlutterEngine with a `FlutterDartProject`.
|
||||
@@ -73,12 +75,12 @@ FLUTTER_EXPORT
|
||||
* @param labelPrefix The label prefix used to identify threads for this instance. Should
|
||||
* be unique across FlutterEngine instances, and is used in instrumentation to label
|
||||
* the threads used by this FlutterEngine.
|
||||
* @param projectOrNil The `FlutterDartProject` to run.
|
||||
* @param project The `FlutterDartProject` to run.
|
||||
* @param allowHeadlessExecution Whether or not to allow this instance to continue
|
||||
* running after passing a nil `FlutterViewController` to `-setViewController:`.
|
||||
*/
|
||||
- (instancetype)initWithName:(NSString*)labelPrefix
|
||||
project:(FlutterDartProject*)projectOrNil
|
||||
project:(nullable FlutterDartProject*)project
|
||||
allowHeadlessExecution:(BOOL)allowHeadlessExecution NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
/**
|
||||
@@ -103,7 +105,7 @@ FLUTTER_EXPORT
|
||||
* tree-shaken by the Dart compiler.
|
||||
* @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
|
||||
*/
|
||||
- (BOOL)runWithEntrypoint:(NSString*)entrypoint;
|
||||
- (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint;
|
||||
|
||||
/**
|
||||
* Runs a Dart program on an Isolate using the specified entrypoint and Dart library,
|
||||
@@ -120,7 +122,7 @@ FLUTTER_EXPORT
|
||||
* this will default to the same library as the `main()` function in the Dart program.
|
||||
* @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise.
|
||||
*/
|
||||
- (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)uri;
|
||||
- (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint libraryURI:(nullable NSString*)uri;
|
||||
|
||||
/**
|
||||
* Destroy running context for an engine.
|
||||
@@ -177,11 +179,15 @@ FLUTTER_EXPORT
|
||||
/**
|
||||
* The `FlutterMethodChannel` used for localization related platform messages, such as
|
||||
* setting the locale.
|
||||
*
|
||||
* Can be nil after `destroyContext` is called.
|
||||
*/
|
||||
@property(nonatomic, readonly) FlutterMethodChannel* localizationChannel;
|
||||
@property(nonatomic, readonly, nullable) FlutterMethodChannel* localizationChannel;
|
||||
/**
|
||||
* The `FlutterMethodChannel` used for navigation related platform messages.
|
||||
*
|
||||
* Can be nil after `destroyContext` is called.
|
||||
*
|
||||
* @see [Navigation
|
||||
* Channel](https://docs.flutter.io/flutter/services/SystemChannels/navigation-constant.html)
|
||||
* @see [Navigator Widget](https://docs.flutter.io/flutter/widgets/Navigator-class.html)
|
||||
@@ -191,6 +197,8 @@ FLUTTER_EXPORT
|
||||
/**
|
||||
* The `FlutterMethodChannel` used for core platform messages, such as
|
||||
* information about the screen orientation.
|
||||
*
|
||||
* Can be nil after `destroyContext` is called.
|
||||
*/
|
||||
@property(nonatomic, readonly) FlutterMethodChannel* platformChannel;
|
||||
|
||||
@@ -198,6 +206,8 @@ FLUTTER_EXPORT
|
||||
* The `FlutterMethodChannel` used to communicate text input events to the
|
||||
* Dart Isolate.
|
||||
*
|
||||
* Can be nil after `destroyContext` is called.
|
||||
*
|
||||
* @see [Text Input
|
||||
* Channel](https://docs.flutter.io/flutter/services/SystemChannels/textInput-constant.html)
|
||||
*/
|
||||
@@ -207,6 +217,8 @@ FLUTTER_EXPORT
|
||||
* The `FlutterBasicMessageChannel` used to communicate app lifecycle events
|
||||
* to the Dart Isolate.
|
||||
*
|
||||
* Can be nil after `destroyContext` is called.
|
||||
*
|
||||
* @see [Lifecycle
|
||||
* Channel](https://docs.flutter.io/flutter/services/SystemChannels/lifecycle-constant.html)
|
||||
*/
|
||||
@@ -216,6 +228,8 @@ FLUTTER_EXPORT
|
||||
* The `FlutterBasicMessageChannel` used for communicating system events, such as
|
||||
* memory pressure events.
|
||||
*
|
||||
* Can be nil after `destroyContext` is called.
|
||||
*
|
||||
* @see [System
|
||||
* Channel](https://docs.flutter.io/flutter/services/SystemChannels/system-constant.html)
|
||||
*/
|
||||
@@ -224,6 +238,8 @@ FLUTTER_EXPORT
|
||||
/**
|
||||
* The `FlutterBasicMessageChannel` used for communicating user settings such as
|
||||
* clock format and text scale.
|
||||
*
|
||||
* Can be nil after `destroyContext` is called.
|
||||
*/
|
||||
@property(nonatomic, readonly) FlutterBasicMessageChannel* settingsChannel;
|
||||
|
||||
@@ -234,7 +250,7 @@ FLUTTER_EXPORT
|
||||
* observatory service is ready. In release mode or before the observatory has
|
||||
* started, it returns `nil`.
|
||||
*/
|
||||
@property(nonatomic, readonly) NSURL* observatoryUrl;
|
||||
@property(nonatomic, readonly, nullable) NSURL* observatoryUrl;
|
||||
|
||||
/**
|
||||
* The `FlutterBinaryMessenger` associated with this FlutterEngine (used for communicating with
|
||||
@@ -247,8 +263,10 @@ FLUTTER_EXPORT
|
||||
*
|
||||
* This property will be nil if the engine is not running.
|
||||
*/
|
||||
@property(nonatomic, readonly, copy) NSString* isolateId;
|
||||
@property(nonatomic, readonly, copy, nullable) NSString* isolateId;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif // FLUTTER_FLUTTERENGINE_H_
|
||||
|
||||
@@ -69,12 +69,12 @@
|
||||
FlutterBinaryMessengerRelay* _binaryMessenger;
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)projectOrNil {
|
||||
return [self initWithName:labelPrefix project:projectOrNil allowHeadlessExecution:YES];
|
||||
- (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project {
|
||||
return [self initWithName:labelPrefix project:project allowHeadlessExecution:YES];
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(NSString*)labelPrefix
|
||||
project:(FlutterDartProject*)projectOrNil
|
||||
project:(FlutterDartProject*)project
|
||||
allowHeadlessExecution:(BOOL)allowHeadlessExecution {
|
||||
self = [super init];
|
||||
NSAssert(self, @"Super init cannot be nil");
|
||||
@@ -85,10 +85,10 @@
|
||||
|
||||
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(self);
|
||||
|
||||
if (projectOrNil == nil)
|
||||
if (project == nil)
|
||||
_dartProject.reset([[FlutterDartProject alloc] init]);
|
||||
else
|
||||
_dartProject.reset([projectOrNil retain]);
|
||||
_dartProject.reset([project retain]);
|
||||
|
||||
_pluginPublications = [NSMutableDictionary new];
|
||||
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());
|
||||
|
||||
Reference in New Issue
Block a user