Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

Commit 58d850f

Browse files
authored
fix: update asset manifest and deps to latest version (#39)
* fix: use AssetManifest.bin, remove deprecated canvaskit and serviceWorkerSettings - Parse AssetManifest.bin (Standard Message Codec) instead of deprecated AssetManifest.json - Remove canvaskit brick variable and preloading - Replace deprecated serviceWorkerSettings with flutter_build_config - Update to Dart 3.5+ and latest dependencies * fix: revert brick version bump * fix: revert load promises * docs: update information about manifest * fix: revert js formatting * chore: update hooks dependencies to latest versions
1 parent 074ae22 commit 58d850f

File tree

6 files changed

+57
-33
lines changed

6 files changed

+57
-33
lines changed

.github/cspell.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
],
2020
"useGitignore": true,
2121
"words": [
22-
"canvaskit",
2322
"Brickhub"
2423
]
2524
}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ to the user.
2727
| `project_title` | The title of the project | `name` attribute in the `pubspec.yaml` |
2828
| `project_description` | The project description | `description` attribute in the `pubspec.yaml` |
2929
| `batch_size` | How many assets will be loaded at the same time | `20` |
30-
| `canvaskit` | If the app uses `canvaskit` mode or not | `true` |
3130

3231
## FAQ
3332

__brick__/web/flutter_bootstrap.js

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,51 @@
22
{{=<% %>=}}{{flutter_js}}<%={{ }}=%>
33
{{=<% %>=}}{{flutter_build_config}}<%={{ }}=%>
44

5-
const progressBar = document.querySelector('#progress-bar');
65
const progressText = document.querySelector('#progress-text');
76
const progressIndicator = document.querySelector('#progress-indicator');
87

98
async function readAssets() {
10-
// NOTE: AssetManifest.json will be deprecated in favour of AssetManifest.bin:
11-
// https://github.com/VeryGoodOpenSource/flutter_web_preloader/issues/28
12-
const response = await fetch('assets/AssetManifest.json');
13-
const manifest = await response.json();
14-
const assets = Object.values(manifest)
15-
.map((list) => list.map((url) => 'assets/' + url))
16-
.reduce((arr, curr) => [...arr, ...curr], []);
9+
// AssetManifest.bin is encoded with Flutter's Standard Message Codec.
10+
// See: https://docs.flutter.dev/platform-integration/web/initialization
11+
// See also: https://docs.flutter.dev/release/breaking-changes/asset-manifest-dot-json#reading-asset-manifest-information-from-dart-code-outside-of-a-flutter-app
12+
// Keep in mind that AssetManifest.bin is an implementation detail of Flutter.
13+
// Reading this file isn't an officially supported workflow. The contents or format of the file might change in a future Flutter release without an announcement.
14+
const response = await fetch('assets/AssetManifest.bin');
15+
const buffer = await response.arrayBuffer();
16+
const view = new DataView(buffer);
17+
let o = 0;
18+
19+
const readByte = () => view.getUint8(o++);
20+
const readSize = () => {
21+
const b = readByte();
22+
if (b < 254) return b;
23+
if (b === 254) { const s = view.getUint16(o, true); o += 2; return s; }
24+
const s = view.getUint32(o, true); o += 4; return s;
25+
};
26+
const readString = () => {
27+
const n = readSize();
28+
const s = new TextDecoder().decode(new Uint8Array(buffer, o, n));
29+
o += n;
30+
return s;
31+
};
32+
const skip = () => {
33+
const t = readByte();
34+
if (t <= 2) return;
35+
if (t === 7 || t === 8) { const n = readSize(); o += n; return; }
36+
if (t === 12) { for (let i = readSize(); i > 0; i--) skip(); return; }
37+
if (t === 13) { for (let i = readSize() * 2; i > 0; i--) skip(); }
38+
};
39+
40+
// The manifest is a map; we only need its keys (the asset paths).
41+
readByte(); // type 13 (map)
42+
const count = readSize();
43+
const assets = [];
44+
for (let i = 0; i < count; i++) {
45+
readByte(); // type 7 (string)
46+
const path = readString();
47+
if (!path.startsWith('packages/')) assets.push(path);
48+
skip();
49+
}
1750
return assets;
1851
}
1952

@@ -29,15 +62,16 @@ async function beginPreloading() {
2962
return;
3063
}
3164

32-
const batchSize = {{batch_size}};
65+
const batchSize = {{ batch_size }
66+
};
3367

34-
progressIndicator.style.width = '0%';
35-
progressText.textContent = `Loaded ${loadedAssets} of ${totalAssets} assets`;
68+
progressIndicator.style.width = '0%';
69+
progressText.textContent = `Loaded ${loadedAssets} of ${totalAssets} assets`;
3670

37-
for (let i = 0; i < assets.length; i += batchSize) {
38-
const batch = assets.slice(i, i + batchSize);
39-
await loadBatch(batch);
40-
}
71+
for (let i = 0; i < assets.length; i += batchSize) {
72+
const batch = assets.slice(i, i + batchSize);
73+
await loadBatch(batch);
74+
}
4175
}
4276

4377
function reportProgress() {
@@ -76,10 +110,7 @@ async function loadBatch(urls) {
76110
}
77111

78112
_flutter.loader.load({
79-
serviceWorkerSettings: {
80-
serviceWorkerVersion: {{=<% %>=}}{{flutter_service_worker_version}}<%={{ }}=%>,
81-
},
82-
onEntrypointLoaded: async function(engineInitializer) {
113+
onEntrypointLoaded: async function (engineInitializer) {
83114
await Promise.all([
84115
beginPreloading(),
85116
engineInitializer.initializeEngine(),

brick.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,3 @@ vars:
2222
description: The number of concurrent loads that the preload will trigger.
2323
default: 20
2424
prompt: Pre load batch size (defaults to 20)?
25-
canvaskit:
26-
type: boolean
27-
description: If the project should pre load canvaskit.
28-
default: true
29-
prompt: Pre load canvas kit (defaults to true)?

hooks/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:very_good_analysis/analysis_options.5.1.0.yaml
1+
include: package:very_good_analysis/analysis_options.10.0.0.yaml

hooks/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: flutter_web_preloader_hooks
22

33
environment:
4-
sdk: ">=2.17.0 <3.0.0"
4+
sdk: ">=3.5.0 <4.0.0"
55

66
dependencies:
7-
mason: ^0.1.1
8-
yaml: ^3.1.1
7+
mason: ^0.1.2
8+
yaml: ^3.1.3
99

1010
dev_dependencies:
11-
mocktail: ^1.0.0
12-
test: ^1.22.2
13-
very_good_analysis: ^5.1.0
11+
mocktail: ^1.0.4
12+
test: ^1.30.0
13+
very_good_analysis: ^10.2.0

0 commit comments

Comments
 (0)