Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d06e9e8

Browse files
jamesderlinchinmaygarde
authored andcommitted
Deprecate -[FlutterDartProject initFromDefaultSourceForConfiguration] (#18886) (#5858)
* Deprecate -[FlutterDartProject initFromDefaultSourceForConfiguration] (#18886) `-[FlutterDartProject initFromDefaultSourceForConfiguration]` no longer seems very useful. It calls `-initWithPrecompiledDartBundle:` or `-initWithFlutterAssets:dartMain:packages:`, but since it now passes `nil` for all arguments, both paths end up doing the same thing. Additionally, `-initFromDefaultSourceForConfiguration` is awkward to use in Swift. The automatically generated Swift interface is: public convenience init!(fromDefaultSourceForConfiguration: ()) and it's not obvious how to call that. Let's deprecate `-initFromDefaultSourceForConfiguration` and instead expect callers to use the existing `-init` method. (We can make `-init` do different things for different build configurations later if necessary.) Bonus: Rename some parameters to make it more obvious when they may be `nil`.
1 parent 3e6b681 commit d06e9e8

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

shell/platform/darwin/ios/framework/Headers/Flutter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
/**
99
BREAKING CHANGES:
1010
11+
July 26, 2018: Marked -[FlutterDartProject
12+
initFromDefaultSourceForConfiguration] deprecated.
13+
1114
February 28, 2018: Removed "initWithFLXArchive" and
1215
"initWithFLXArchiveWithScriptSnapshot".
1316

shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ FLUTTER_EXPORT
2121
- (instancetype)initWithFlutterAssetsWithScriptSnapshot:(NSURL*)flutterAssetsURL
2222
NS_DESIGNATED_INITIALIZER;
2323

24-
- (instancetype)initFromDefaultSourceForConfiguration;
24+
- (instancetype)initFromDefaultSourceForConfiguration FLUTTER_DEPRECATED("Use -init instead.");
2525

2626
/**
2727
Returns the file name for the given asset.

shell/platform/darwin/ios/framework/Headers/FlutterViewController.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
#include "FlutterTexture.h"
1616

1717
FLUTTER_EXPORT
18-
@interface FlutterViewController : UIViewController<FlutterBinaryMessenger, FlutterTextureRegistry, FlutterPluginRegistry>
18+
@interface FlutterViewController
19+
: UIViewController <FlutterBinaryMessenger, FlutterTextureRegistry, FlutterPluginRegistry>
1920

20-
- (instancetype)initWithProject:(FlutterDartProject*)project
21+
- (instancetype)initWithProject:(FlutterDartProject*)projectOrNil
2122
nibName:(NSString*)nibNameOrNil
2223
bundle:(NSBundle*)nibBundleOrNil NS_DESIGNATED_INITIALIZER;
2324

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@ - (instancetype)initWithFlutterAssets:(NSURL*)flutterAssetsURL
158158
if (self) {
159159
_settings = DefaultSettingsForProcess();
160160

161-
if ([[NSFileManager defaultManager] fileExistsAtPath:dartMainURL.path]) {
161+
if (dartMainURL != nil && [[NSFileManager defaultManager] fileExistsAtPath:dartMainURL.path]) {
162162
_settings.main_dart_file_path = dartMainURL.path.UTF8String;
163163
}
164164

165-
if ([[NSFileManager defaultManager] fileExistsAtPath:dartPackages.path]) {
165+
if (dartPackages.path != nil &&
166+
[[NSFileManager defaultManager] fileExistsAtPath:dartPackages.path]) {
166167
_settings.packages_file_path = dartPackages.path.UTF8String;
167168
}
168169
}
@@ -176,7 +177,8 @@ - (instancetype)initWithFlutterAssetsWithScriptSnapshot:(NSURL*)flutterAssetsURL
176177
if (self) {
177178
_settings = DefaultSettingsForProcess();
178179

179-
if ([[NSFileManager defaultManager] fileExistsAtPath:flutterAssetsURL.path]) {
180+
if (flutterAssetsURL != nil &&
181+
[[NSFileManager defaultManager] fileExistsAtPath:flutterAssetsURL.path]) {
180182
_settings.assets_path = flutterAssetsURL.path.UTF8String;
181183

182184
NSURL* scriptSnapshotPath =
@@ -192,12 +194,9 @@ - (instancetype)initWithFlutterAssetsWithScriptSnapshot:(NSURL*)flutterAssetsURL
192194

193195
#pragma mark - Convenience initializers
194196

197+
// Exists for backward-compatibility. Expect this to be removed.
195198
- (instancetype)initFromDefaultSourceForConfiguration {
196-
if (blink::DartVM::IsRunningPrecompiledCode()) {
197-
return [self initWithPrecompiledDartBundle:nil];
198-
} else {
199-
return [self initWithFlutterAssets:nil dartMain:nil packages:nil];
200-
}
199+
return [self init];
201200
}
202201

203202
- (const blink::Settings&)settings {

shell/platform/darwin/ios/framework/Source/FlutterHeadlessDartRunner.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ - (void)runWithEntrypointAndCallback:(NSString*)entrypoint
9393
return;
9494
}
9595

96-
FlutterDartProject* project =
97-
[[[FlutterDartProject alloc] initFromDefaultSourceForConfiguration] autorelease];
96+
FlutterDartProject* project = [[[FlutterDartProject alloc] init] autorelease];
9897

9998
auto config = project.runConfiguration;
10099
config.SetEntrypointAndLibrary(entrypoint.UTF8String, uri.UTF8String);

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ @implementation FlutterViewController {
6060

6161
#pragma mark - Manage and override all designated initializers
6262

63-
- (instancetype)initWithProject:(FlutterDartProject*)project
63+
- (instancetype)initWithProject:(FlutterDartProject*)projectOrNil
6464
nibName:(NSString*)nibNameOrNil
6565
bundle:(NSBundle*)nibBundleOrNil {
6666
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
6767

6868
if (self) {
69-
if (project == nil)
70-
_dartProject.reset([[FlutterDartProject alloc] initFromDefaultSourceForConfiguration]);
69+
if (projectOrNil == nil)
70+
_dartProject.reset([[FlutterDartProject alloc] init]);
7171
else
72-
_dartProject.reset([project retain]);
72+
_dartProject.reset([projectOrNil retain]);
7373

7474
[self performCommonViewControllerInitialization];
7575
}

0 commit comments

Comments
 (0)