skip to Main Content

I just upgraded to Flutter 3.22.0 and am getting the following error when running my Flutter web app on chrome:

Warning: In index.html:84: Local variable for "serviceWorkerVersion" is deprecated.
Use "{{flutter_service_worker_version}}" template token instead.

Any ideas on how to fix this?

2

Answers


  1. Chosen as BEST ANSWER

    I fixed this by comparing my old index.html to a newly created empty Flutter 3.22 project.

    In my case the old index.html body contained something like the following:

    <body>
      <!-- This script installs service_worker.js to provide PWA 
      functionality to application. For more information, see: 
      https://developers.google.com/web/fundamentals/primers/service-workers -->
      <script>
        var serviceWorkerVersion = null;
        var scriptLoaded = false;
    
        function loadMainDartJs() {...}
        if ('serviceWorker' in navigator) {..} 
        else {...}
      </script>
    </body>
    

    The empty Flutter 3.22 project only contained a single line.

    <body>
      <script src="flutter_bootstrap.js" async></script>
    </body>
    

    I just replaced the long script with the short one from the latest Flutter version (as outlined by the Flutter team here) and things seem to be working now.


  2. Martin Reindl’s answer works pretty well!

    Do not try to manually edit the index.html adding the missing variable or changing function names cause the flutter dev env will not start.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search