Skip to content

Commit

Permalink
Update "Flutter web app initialization" page (#11369)
Browse files Browse the repository at this point in the history
Resolves #11320
Resolves #11321

cc: @kevmoo
  • Loading branch information
johnpryan authored Nov 12, 2024
1 parent 171b3b9 commit e47bbab
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 308 deletions.
1 change: 1 addition & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
{ "source": "/platform-integration/ios/splash-screen", "destination": "/platform-integration/ios/launch-screen", "type": 301 },
{ "source": "/platform-integration/platform-views", "destination": "/platform-integration/android/platform-views", "type": 301 },
{ "source": "/platform-integration/web-images", "destination": "/platform-integration/web/web-images", "type": 301 },
{ "source": "/platform-integration/web/initialization-legacy", "destination": "/platform-integration/web/initialization", "type": 301 },
{ "source": "/platform-integration/web/bootstrapping", "destination": "/platform-integration/web/initialization", "type": 301 },
{ "source": "/platform-integration/windows/run-loop-migration", "destination": "/release/breaking-changes/windows-run-loop", "type": 301 },
{ "source": "/platform-integration/windows/version-migration", "destination": "/release/breaking-changes/windows-version-information", "type": 301 },
Expand Down
8 changes: 0 additions & 8 deletions src/content/platform-integration/web/embedding-flutter-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,4 @@ _flutter.loader.load({
To learn more about other configuration options,
check out [Customizing web app initialization][].

:::version-note
This method of specifying the `hostElement` is superseded by the
**Embedded mode** described above, **please consider migrating to it**.
To learn how to configure the `hostElement` in earlier Flutter versions,
reference [Legacy web app initialization][].
:::

[Customizing web app initialization]: {{site.docs}}/platform-integration/web/initialization
[Legacy web app initialization]: {{site.docs}}/platform-integration/web/initialization-legacy
250 changes: 0 additions & 250 deletions src/content/platform-integration/web/initialization-legacy.md

This file was deleted.

50 changes: 7 additions & 43 deletions src/content/platform-integration/web/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ title: Flutter web app initialization
description: Customize how Flutter apps are initialized on the web.
---

:::note
This page describes APIs that are available in Flutter 3.22 and later.
To customize web app initialization in Flutter 3.21 or earlier,
check out the previous [Customizing web app initialization][] documentation.
:::
This page details the initialization process for Flutter web apps and
how it can be customized.

[Customizing web app initialization]: /platform-integration/web/initialization-legacy
## Bootstrapping

This page details the initialization process for Flutter web apps, and
how this process can be customized.

## `flutter_bootstrap.js`

When building your flutter app, the `flutter build web` command produces
The `flutter build web` command produces
a script called `flutter_bootstrap.js` in
the build output directory (`build/web`).
This file contains the JavaScript code needed to initialize and
Expand Down Expand Up @@ -88,7 +80,7 @@ substitute in either the `flutter_bootstrap.js` or `index.html` files:

<a id="write-a-custom-flutter_bootstrap-js" aria-hidden="true"></a>

## Write a custom `flutter_bootstrap.js` {:#custom-bootstrap-js}
## Write a custom bootstrap script {:#custom-bootstrap-js}

Any custom `flutter_bootstrap.js` script needs to have three components in
order to successfully start your Flutter app:
Expand All @@ -109,7 +101,7 @@ The most basic `flutter_bootstrap.js` file would look something like this:
_flutter.loader.load();
```

## The `_flutter.loader.load()` API
## Customize the Flutter Loader

The `_flutter.loader.load()` JavaScript API can be invoked with optional
arguments to customize initialization behavior:
Expand All @@ -118,7 +110,6 @@ arguments to customize initialization behavior:
|-------------------------|-------------------------------------------------------------------------------------------------------------------------------|--------------|
| `config` | The Flutter configuration of your app. | `Object` |
| `onEntrypointLoaded` | The function called when the engine is ready to be initialized. Receives an `engineInitializer` object as its only parameter. | `Function` |
| `serviceWorkerSettings` | The configuration for the `flutter_service_worker.js` loader. (If not set, the service worker isn't used.) | `Object` |

{:.table}

Expand All @@ -140,16 +131,6 @@ The `config` argument is an object that can have the following optional fields:

[web-renderers]: /platform-integration/web/renderers

The `serviceWorkerSettings` argument has the following optional fields.

| Name | Description | JS&nbsp;type |
|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|--------------|
| `serviceWorkerUrl` | The URL of the Service Worker JS file. The `serviceWorkerVersion` is appended to the URL. Defaults to `"flutter_service_worker.js?v="`. | `String` |
| `serviceWorkerVersion` | Pass *the `serviceWorkerVersion` variable* set by the build process in your **`index.html`** file. | `String` |
| `timeoutMillis` | The timeout value for the service worker load. Defaults to `4000`. | `Number` |

{:.table}

## Example: Customizing Flutter configuration based on URL query parameters

The following example shows a custom `flutter_bootstrap.js` that allows
Expand All @@ -165,9 +146,6 @@ const renderer = searchParams.get('renderer');
const userConfig = renderer ? {'renderer': renderer} : {};
_flutter.loader.load({
config: userConfig,
serviceWorkerSettings: {
serviceWorkerVersion: {% raw %}{{flutter_service_worker_version}}{% endraw %},
},
});
```

Expand All @@ -177,7 +155,7 @@ changes the user configuration of the Flutter app.
It also passes the service worker settings to use the flutter service worker,
along with the service worker version.

## The `onEntrypointLoaded` callback
## The onEntrypointLoaded callback

You can also pass an `onEntrypointLoaded` callback into the `load` API in order
to perform custom logic at different parts of the initialization process.
Expand Down Expand Up @@ -234,17 +212,3 @@ _flutter.loader.load({
}
});
```

## Upgrade an older project

If your project was created in Flutter 3.21 or earlier, you can create a new
`index.html` file with the latest initialization template by running
`flutter create` as follows.

First, remove the files from your `/web` directory.

Then, from your project directory, run the following:

```console
$ flutter create . --platforms=web
```
7 changes: 0 additions & 7 deletions src/content/platform-integration/web/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,8 @@ The web renderer can't be changed after calling the `load` method. Therefore,
any decisions about which renderer to use, must be made prior to calling
`_flutter.loader.load`.

:::version-note
The method of specifying the web renderer was changed in Flutter 3.22.
To learn how to configure the renderer in earlier Flutter versions,
check out [Legacy web app initialization][web-init-legacy].
:::

[custom-bootstrap]: /platform-integration/web/initialization#custom-bootstrap-js
[customizing-web-init]: /platform-integration/web/initialization
[web-init-legacy]: /platform-integration/web/initialization-legacy

## Choosing which build mode to use

Expand Down

0 comments on commit e47bbab

Please sign in to comment.