Skip to content

[web] support offline PWA #60069

Closed as not planned
Closed as not planned

Description

@Mateis

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

  1. added
    d: stackoverflow
    platform-web
    c: proposal
    c: new feature
    and removed on Jun 26, 2020
  2. yjbanov commented on Jun 26, 2020

    @yjbanov
    Contributor

    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.

  3. added
    P2
    on Jun 26, 2020
  4. added
    framework
    on Jul 8, 2020
  5. added
    engine
    and removed
    d: stackoverflow
    framework
    on Jan 21, 2021
  6. 48 remaining items

  7. hectorAguero commented on Apr 17, 2024

    @hectorAguero

    Is this still an issue?

    I just ran flutter build web --pwa-strategy=offline-first and offline works, at least on ios 17.4+
    Same for flutter build web --no-web-resources-cdn

    Not 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

  8. RelicOfTesla commented on Apr 18, 2024

    @RelicOfTesla

    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

  9. seanchann commented on Aug 12, 2024

    @seanchann

    any updates?

  10. MengLizhi commented on Nov 22, 2024

    @MengLizhi

    Strongly request to add a method or configuration to turn off the feature of Flutter Web automatically downloading remote fonts

  11. nimashahahmadian commented on Nov 22, 2024

    @nimashahahmadian

    @MengLizhi I think
    --no-web-resources-cdn
    Would do what you want

  12. kbot commented on Mar 27, 2025

    @kbot

    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.

      # Embed web fonts
      fonts:
        - family: Roboto
          fonts:
            - asset: assets/web/fonts/Roboto-Regular.ttf
            - asset: assets/web/fonts/Roboto-Thin.ttf
              weight: 100
            - asset: assets/web/fonts/Roboto-ThinItalic.ttf
              weight: 100
              style: italic
            - asset: assets/web/fonts/Roboto-Light.ttf
              weight: 300
            - asset: assets/web/fonts/Roboto-LightItalic.ttf
              weight: 300
              style: italic
            - asset: assets/web/fonts/Roboto-Italic.ttf
              weight: 400
              style: italic
            - asset: assets/web/fonts/Roboto-Medium.ttf
              weight: 500
            - asset: assets/web/fonts/Roboto-MediumItalic.ttf
              weight: 500
              style: italic
            - asset: assets/web/fonts/Roboto-Bold.ttf
              weight: 700
            - asset: assets/web/fonts/Roboto-BoldItalic.ttf
              weight: 700
              style: italic
            - asset: assets/web/fonts/Roboto-Black.ttf
              weight: 900
            - asset: assets/web/fonts/Roboto-BlackItalic.ttf
              weight: 900
              style: italic
        - family: NotoSans
          fonts:
            - asset: assets/web/fonts/NotoSans-Regular.ttf
        - family: NotoSansSymbols
          fonts:
            - asset: assets/web/fonts/NotoSansSymbols-Regular.ttf
    

    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 required for offline mode to block font fetching
      if (event.request.url.includes('fonts.gstatic.com')) {
        console.log('Intercepting request to fonts.gstatic.com:', event.request.url);
        if (event.request.url.includes('notosanssymbols')) {
          return event.respondWith(fetch('/assets/assets/web/fonts/NotoSansSymbols-Regular.ttf'));
        } else if (event.request.url.includes('notosans')) {
          return event.respondWith(fetch('/assets/assets/web/fonts/NotoSans-Regular.ttf'));
        }
        return event.respondWith(fetch('/assets/assets/web/fonts/Roboto-Regular.ttf'));
      }
    

    This is an extreme hack that I would like to remove, but I also can't have my flutter app melting CPUs.

  13. belrka commented on Apr 1, 2025

    @belrka

    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.

    if(s==null)s=null}return s===!0},
    gGy(){var s=this.b
    if(s==null)s=null
    else{s=s.fontFallbackBaseUrl
    if(s==null)s=null}return s==null?"https://fonts.gstatic.com/s/":s}}
    A.M4.prototype={
    gmb(a){var s,r,q=this.d
    if(q==null){s=self.window.devicePixelRatio
    if(s===0)s=1

    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.woff2

    This is also an extreme hack, but I hope this bug will be fixed soon.

  14. FeodorFitsner commented on Apr 10, 2025

    @FeodorFitsner

    I've found a better solution, without modifying service worker or main.dart.js!

    1. Download roboto.woff2 from its original https://fonts.gstatic.com URL (or download Roboto font in .ttf format from Google Fonts) and save it to /assets/fonts/ directory of a Flutter web app.
    2. Edit /assets/FontManifest.json and add a definition for Roboto family, 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, not https://fonts.gstatic.com.

    Enjoy!

  15. albertmoravec commented on May 15, 2025

    @albertmoravec

    trying to use any of these characters, which render fine on mobile/desktop, will cause this infinite loop fetching notosanssymbols: ° Θ ™

    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.

  16. watho commented on Jun 5, 2025

    @watho

    I've found a better solution, without modifying service worker or main.dart.js!

    1. Download `roboto.woff2` from its original `https://fonts.gstatic.com` URL (or download Roboto font in `.ttf` format from Google Fonts) and save it to `/assets/fonts/` directory of a Flutter web app.
    
    2. Edit `/assets/FontManifest.json` and add a definition for `Roboto` family, so it looks like this:
    

    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?

    {
            "family": "NotoSansSymbols",
            "fonts": [
                {
                    "asset": "fonts/notosanssymbols.woff2"
                }
            ]
    },
    
  17. kevmoo commented on Mar 7, 2026

    @kevmoo
    Contributor

    We deprecated the PWA strategy here: #177613

  18. github-actions commented on Mar 21, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2c: new featurec: proposalcustomer: crowdengineplatform-webteam-webtriaged-web

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions