Skip to content

Commit 02ab7b4

Browse files
committed
docs: Add demo page
1 parent e507a98 commit 02ab7b4

18 files changed

+78752
-47
lines changed

docs/.last_build_id

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f9e96ef7e996da76bb77034bd0594bd4

docs/assets/AssetManifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

docs/assets/FontManifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"family":"MaterialIcons","fonts":[{"asset":"fonts/MaterialIcons-Regular.otf"}]}]

docs/assets/NOTICES

Lines changed: 15234 additions & 0 deletions
Large diffs are not rendered by default.
898 KB
Binary file not shown.

docs/favicon.png

917 Bytes
Loading

docs/flutter_service_worker.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
'use strict';
2+
const MANIFEST = 'flutter-app-manifest';
3+
const TEMP = 'flutter-temp-cache';
4+
const CACHE_NAME = 'flutter-app-cache';
5+
const RESOURCES = {
6+
"version.json": "4b6db237b3514a88107a422469adfb0f",
7+
"index.html": "b1f99349019abc6ce46e2df7cc80ee16",
8+
"/": "b1f99349019abc6ce46e2df7cc80ee16",
9+
"main.dart.js": "d449113525dc3c4122f95dc76f811f8b",
10+
"favicon.png": "5dcef449791fa27946b3d35ad8803796",
11+
"icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1",
12+
"icons/Icon-512.png": "96e752610906ba2a93c65f8abe1645f1",
13+
"manifest.json": "15f73b7e8a8209c2206210b3ac8dea1b",
14+
"assets/AssetManifest.json": "99914b932bd37a50b983c5e7c90ae93b",
15+
"assets/NOTICES": "806e613ebfffa8b0d59a5f7e64a45682",
16+
"assets/FontManifest.json": "7b2a36307916a9721811788013e65289",
17+
"assets/fonts/MaterialIcons-Regular.otf": "1288c9e28052e028aba623321f7826ac"
18+
};
19+
20+
// The application shell files that are downloaded before a service worker can
21+
// start.
22+
const CORE = [
23+
"/",
24+
"main.dart.js",
25+
"index.html",
26+
"assets/NOTICES",
27+
"assets/AssetManifest.json",
28+
"assets/FontManifest.json"];
29+
// During install, the TEMP cache is populated with the application shell files.
30+
self.addEventListener("install", (event) => {
31+
self.skipWaiting();
32+
return event.waitUntil(
33+
caches.open(TEMP).then((cache) => {
34+
return cache.addAll(
35+
CORE.map((value) => new Request(value + '?revision=' + RESOURCES[value], {'cache': 'reload'})));
36+
})
37+
);
38+
});
39+
40+
// During activate, the cache is populated with the temp files downloaded in
41+
// install. If this service worker is upgrading from one with a saved
42+
// MANIFEST, then use this to retain unchanged resource files.
43+
self.addEventListener("activate", function(event) {
44+
return event.waitUntil(async function() {
45+
try {
46+
var contentCache = await caches.open(CACHE_NAME);
47+
var tempCache = await caches.open(TEMP);
48+
var manifestCache = await caches.open(MANIFEST);
49+
var manifest = await manifestCache.match('manifest');
50+
// When there is no prior manifest, clear the entire cache.
51+
if (!manifest) {
52+
await caches.delete(CACHE_NAME);
53+
contentCache = await caches.open(CACHE_NAME);
54+
for (var request of await tempCache.keys()) {
55+
var response = await tempCache.match(request);
56+
await contentCache.put(request, response);
57+
}
58+
await caches.delete(TEMP);
59+
// Save the manifest to make future upgrades efficient.
60+
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
61+
return;
62+
}
63+
var oldManifest = await manifest.json();
64+
var origin = self.location.origin;
65+
for (var request of await contentCache.keys()) {
66+
var key = request.url.substring(origin.length + 1);
67+
if (key == "") {
68+
key = "/";
69+
}
70+
// If a resource from the old manifest is not in the new cache, or if
71+
// the MD5 sum has changed, delete it. Otherwise the resource is left
72+
// in the cache and can be reused by the new service worker.
73+
if (!RESOURCES[key] || RESOURCES[key] != oldManifest[key]) {
74+
await contentCache.delete(request);
75+
}
76+
}
77+
// Populate the cache with the app shell TEMP files, potentially overwriting
78+
// cache files preserved above.
79+
for (var request of await tempCache.keys()) {
80+
var response = await tempCache.match(request);
81+
await contentCache.put(request, response);
82+
}
83+
await caches.delete(TEMP);
84+
// Save the manifest to make future upgrades efficient.
85+
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
86+
return;
87+
} catch (err) {
88+
// On an unhandled exception the state of the cache cannot be guaranteed.
89+
console.error('Failed to upgrade service worker: ' + err);
90+
await caches.delete(CACHE_NAME);
91+
await caches.delete(TEMP);
92+
await caches.delete(MANIFEST);
93+
}
94+
}());
95+
});
96+
97+
// The fetch handler redirects requests for RESOURCE files to the service
98+
// worker cache.
99+
self.addEventListener("fetch", (event) => {
100+
if (event.request.method !== 'GET') {
101+
return;
102+
}
103+
var origin = self.location.origin;
104+
var key = event.request.url.substring(origin.length + 1);
105+
// Redirect URLs to the index.html
106+
if (key.indexOf('?v=') != -1) {
107+
key = key.split('?v=')[0];
108+
}
109+
if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '') {
110+
key = '/';
111+
}
112+
// If the URL is not the RESOURCE list then return to signal that the
113+
// browser should take over.
114+
if (!RESOURCES[key]) {
115+
return;
116+
}
117+
// If the URL is the index.html, perform an online-first request.
118+
if (key == '/') {
119+
return onlineFirst(event);
120+
}
121+
event.respondWith(caches.open(CACHE_NAME)
122+
.then((cache) => {
123+
return cache.match(event.request).then((response) => {
124+
// Either respond with the cached resource, or perform a fetch and
125+
// lazily populate the cache.
126+
return response || fetch(event.request).then((response) => {
127+
cache.put(event.request, response.clone());
128+
return response;
129+
});
130+
})
131+
})
132+
);
133+
});
134+
135+
self.addEventListener('message', (event) => {
136+
// SkipWaiting can be used to immediately activate a waiting service worker.
137+
// This will also require a page refresh triggered by the main worker.
138+
if (event.data === 'skipWaiting') {
139+
self.skipWaiting();
140+
return;
141+
}
142+
if (event.data === 'downloadOffline') {
143+
downloadOffline();
144+
return;
145+
}
146+
});
147+
148+
// Download offline will check the RESOURCES for all files not in the cache
149+
// and populate them.
150+
async function downloadOffline() {
151+
var resources = [];
152+
var contentCache = await caches.open(CACHE_NAME);
153+
var currentContent = {};
154+
for (var request of await contentCache.keys()) {
155+
var key = request.url.substring(origin.length + 1);
156+
if (key == "") {
157+
key = "/";
158+
}
159+
currentContent[key] = true;
160+
}
161+
for (var resourceKey of Object.keys(RESOURCES)) {
162+
if (!currentContent[resourceKey]) {
163+
resources.push(resourceKey);
164+
}
165+
}
166+
return contentCache.addAll(resources);
167+
}
168+
169+
// Attempt to download the resource online before falling back to
170+
// the offline cache.
171+
function onlineFirst(event) {
172+
return event.respondWith(
173+
fetch(event.request).then((response) => {
174+
return caches.open(CACHE_NAME).then((cache) => {
175+
cache.put(event.request, response.clone());
176+
return response;
177+
});
178+
}).catch((error) => {
179+
return caches.open(CACHE_NAME).then((cache) => {
180+
return cache.match(event.request).then((response) => {
181+
if (response != null) {
182+
return response;
183+
}
184+
throw error;
185+
});
186+
});
187+
})
188+
);
189+
}

docs/icons/Icon-192.png

5.17 KB
Loading

docs/icons/Icon-512.png

8.06 KB
Loading

docs/index.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<!--
5+
If you are serving your web app in a path other than the root, change the
6+
href value below to reflect the base path you are serving from.
7+
8+
The path provided below has to start and end with a slash "/" in order for
9+
it to work correctly.
10+
11+
Fore more details:
12+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
13+
-->
14+
<base href="/storybook_flutter/">
15+
16+
<meta charset="UTF-8">
17+
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
18+
<meta name="description" content="A new Flutter project.">
19+
20+
<!-- iOS meta tags & icons -->
21+
<meta name="apple-mobile-web-app-capable" content="yes">
22+
<meta name="apple-mobile-web-app-status-bar-style" content="black">
23+
<meta name="apple-mobile-web-app-title" content="example">
24+
<link rel="apple-touch-icon" href="icons/Icon-192.png">
25+
26+
<!-- Favicon -->
27+
<link rel="icon" type="image/png" href="favicon.png"/>
28+
29+
<title>example</title>
30+
<link rel="manifest" href="manifest.json">
31+
</head>
32+
<body>
33+
<!-- This script installs service_worker.js to provide PWA functionality to
34+
application. For more information, see:
35+
https://developers.google.com/web/fundamentals/primers/service-workers -->
36+
<script>
37+
if ('serviceWorker' in navigator) {
38+
window.addEventListener('flutter-first-frame', function () {
39+
navigator.serviceWorker.register('flutter_service_worker.js?v=229552938');
40+
});
41+
}
42+
</script>
43+
<script src="main.dart.js" type="application/javascript"></script>
44+
</body>
45+
</html>

0 commit comments

Comments
 (0)