Repository navigation
Description
I would like to create a PWA app that's offline available.
To test this feature I have enabled web support flutter config --enable-web, created a default demo app using flutter create pwatest and made it available on my phone through my local network with flutter run -d chrome web-hostname=192.168.43.59 --web-port=80. I succesfully load the webapp on my mobile, 'add to home screen', and open the PWA-app.
Issue: when I tap open my PWA-app on the homescreen, it tries to connect to my local flutter server (192.168.43.59) and cannot find it (which is correct, because it is now offline). When I turn off my phone internet, it just shows a default 'Flutter Demo' screen. Hence, my app is not offline available.
Is this expected behavior and how do I make my PWA app offline available?
Flutter doctor:
[√] Flutter (Channel beta, 1.19.0-4.1.pre, on Microsoft Windows [Version 10.0.18363.900], locale nl-NL)
• Flutter version 1.19.0-4.1.pre at C:\src\flutter
• Framework revision f994b76974 (13 days ago), 2020-06-09 15:53:13 -0700
• Engine revision 9a28c3bcf4
• Dart version 2.9.0 (build 2.9.0-14.1.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\matre\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] VS Code (version 1.46.1)
• VS Code at C:\Users\matre\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.11.0
[√] Connected device (2 available)
• Web Server • web-server • web-javascript • Flutter Tools
• Chrome • chrome • web-javascript • Google Chrome 83.0.4103.106
• No issues found!
Activity
yjbanov commentedon Jun 26, 2020
Our out-of-the-box experience is not polished yet. A workaround is to write your own service worker. There are some guidelines around making PWAs offline-capable:
However, we should still fix this and give you an ergonomic way for making your Flutter PWA offline-capable.
48 remaining items
hectorAguero commentedon Apr 17, 2024
Is this still an issue?
I just ran
flutter build web --pwa-strategy=offline-firstand offline works, at least on ios 17.4+Same for
flutter build web --no-web-resources-cdnNot sure what is the difference, but for offline to work, these commands pass the canvasKitBaseUrl instead of relying on a cdn.
For some server like github pages for example, you need to pass the href, or put the canvasKitBaseUrl config in the main.js or the flutter_bootstrap.js(with the new template).
Also, in current beta if I add
--wasm, it works in all browsers, even if they dont support wasm(they use the other render)PS: Use custom fonts it's seem still a problem though
RelicOfTesla commentedon Apr 18, 2024
https://github.com/flutter/engine/blob/5687011d5e949d475a867b742f2e628f3bfbec05/lib/web_ui/lib/src/engine/canvaskit/fonts.dart#L105-L124
Always download the Roboto font (Roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw. ttf) when Roboto is not loaded.
This is a static code that is not related to compile or startup parameters.Even if you don't use it.
You must add the "Roboto" font family in pubspec.yaml
In addition, if there are unrecognizable characters, the font will also be downloaded.
https://github.com/flutter/engine/blob/main/lib/web_ui/lib/src/engine/font_fallbacks.dart
seanchann commentedon Aug 12, 2024
any updates?
MengLizhi commentedon Nov 22, 2024
Strongly request to add a method or configuration to turn off the feature of Flutter Web automatically downloading remote fonts
nimashahahmadian commentedon Nov 22, 2024
@MengLizhi I think
--no-web-resources-cdn
Would do what you want
kbot commentedon Mar 27, 2025
Fonts are definitely still an issue when using
--no-web-resources-cdn, which only affects the canvaskit source. The fact that this loops indefinitely trying to download fonts is really bad behavior.Trying to provide fonts via pubspec.yaml also doesn't seem to work in some cases.
trying to use any of these characters, which render fine on mobile/desktop, will cause this infinite loop fetching notosanssymbols: ° Θ ™
I was only able to stop this is modify the service worker fetch listener to return my local files when static is fetched:
This is an extreme hack that I would like to remove, but I also can't have my flutter app melting CPUs.
belrka commentedon Apr 1, 2025
Unfortunately, the variant with the modified service worker did not work for me, but I have found another workaround.
You can search for the link for the font (
https://fonts.gstatic.com/s/) in main.dart.js after building it and replace it with your own.However, it must be noted that Dart adds the file name and two path segments.
The file must therefore have a special name on the server and be stored under a specific path.
I use Flutter version 3.29.2 and in my case it was the following path that was added:
roboto/v32/KFOmCnqEu92Fr1Me4GZLCzYlKw.woff2This is also an extreme hack, but I hope this bug will be fixed soon.
FeodorFitsner commentedon Apr 10, 2025
I've found a better solution, without modifying service worker or
main.dart.js!roboto.woff2from its originalhttps://fonts.gstatic.comURL (or download Roboto font in.ttfformat from Google Fonts) and save it to/assets/fonts/directory of a Flutter web app./assets/FontManifest.jsonand add a definition forRobotofamily, so it looks like this:[ { "family": "Roboto", "fonts": [ { "asset": "fonts/roboto.woff2" } ] }, { "family": "MaterialIcons", "fonts": [ { "asset": "fonts/MaterialIcons-Regular.otf" } ] }, { "family": "packages/cupertino_icons/CupertinoIcons", "fonts": [ { "asset": "packages/cupertino_icons/assets/CupertinoIcons.ttf" } ] } ]Roboto font will be downloaded from
/assets/fonts/roboto.woff2, nothttps://fonts.gstatic.com.Enjoy!
albertmoravec commentedon May 15, 2025
Just so that it is tracked somewhere, I observed similar behavior when using Chinese characters while my primary font did not support Chinese. The engine tried to fetch Noto Sans Simplified Chinese and ended up causing an infinite loop.
watho commentedon Jun 5, 2025
For me this only works for the roboto font. The same approach for the Noto Sans Symbols font still results in an endless fetching loop. What can i do to prevent this?
kevmoo commentedon Mar 7, 2026
We deprecated the PWA strategy here: #177613
github-actions commentedon Mar 21, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.