Skip to content

Commit 247e411

Browse files
authored
Fix initial route documentation for iOS (#4578)
1 parent 090c6ba commit 247e411

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/docs/development/add-to-app/ios/add-flutter-screen.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -422,45 +422,52 @@ flutterEngine.run(withEntrypoint: "myOtherEntrypoint", libraryURI: "other_file.d
422422

423423
### Route
424424

425-
An initial route can be set for your Flutter [`WidgetsApp`][]
426-
when constructing the engine.
425+
Starting in Flutter version 1.22, an initial route can be set for your Flutter
426+
[`WidgetsApp`][] when constructing the FlutterEngine or the
427+
FlutterViewController.
427428

428429
{% samplecode initial-route %}
429430
{% sample Objective-C %}
430431
<!--code-excerpt "Creating engine" title-->
431432
```objectivec
432-
FlutterEngine *flutterEngine =
433-
[[FlutterEngine alloc] initWithName:@"my flutter engine"];
434-
[[flutterEngine navigationChannel] invokeMethod:@"setInitialRoute"
435-
arguments:@"/onboarding"];
436-
[flutterEngine run];
433+
FlutterEngine *flutterEngine = [[FlutterEngine alloc] init];
434+
// FlutterDefaultDartEntrypoint is the same as nil, which will run main().
435+
[flutterEngine runWithEntrypoint:FlutterDefaultDartEntrypoint
436+
initialRoute:@"/onboarding"];
437437
```
438438
{% sample Swift %}
439439
<!--code-excerpt "Creating engine" title-->
440440
```swift
441-
let flutterEngine = FlutterEngine(name: "my flutter engine")
442-
flutterEngine.navigationChannel.invokeMethod("setInitialRoute", arguments:"/onboarding")
443-
flutterEngine.run()
441+
let flutterEngine = FlutterEngine()
442+
// FlutterDefaultDartEntrypoint is the same as nil, which will run main().
443+
engine.run(
444+
withEntrypoint: FlutterDefaultDartEntrypoint, initialRoute: "/onboarding")
444445
```
445446
{% endsamplecode %}
446447

447448
This code sets your `dart:ui`'s [`window.defaultRouteName`][]
448449
to `"/onboarding"` instead of `"/"`.
449450

450-
{{site.alert.warning}}
451-
`"setInitialRoute"` on the `navigationChannel` must be called
452-
before running your `FlutterEngine` in order for Flutter's
453-
first frame to use the desired route.
451+
Alternatively, to construct a FlutterViewController directly without pre-warming
452+
a FlutterEngine:
454453

455-
Specifically, this must be called before running the Dart entrypoint.
456-
The entrypoint may lead to a series of events where
457-
[`runApp`][] builds a Material/Cupertino/WidgetsApp
458-
that implicitly creates a [Navigator][] that might
459-
`window.defaultRouteName` when the [`NavigatorState`][] is
460-
first initialized.
461-
462-
Setting the initial route after running the engine doesn't have an effect.
463-
{{site.alert.end}}
454+
{% samplecode initial-route %}
455+
{% sample Objective-C %}
456+
<!--code-excerpt "Creating view controller" title-->
457+
```objectivec
458+
FlutterViewController* flutterViewController =
459+
[[FlutterViewController alloc] initWithProject:nil
460+
initialRoute:@"/onboarding"
461+
nibName:nil
462+
bundle:nil];
463+
```
464+
{% sample Swift %}
465+
<!--code-excerpt "Creating view controller" title-->
466+
```swift
467+
let flutterViewController = FlutterViewController(
468+
project: nil, initialRoute: "/onboarding", nibName: nil, bundle: nil)
469+
```
470+
{% endsamplecode %}
464471

465472
{{site.alert.tip}}
466473
In order to imperatively change your current Flutter

0 commit comments

Comments
 (0)