未验证 提交 8cdb3afd 编写于 作者: X xster 提交者: GitHub

Annotate nullability on FlutterEngine to make swift writing more ergonomic (#11808)

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