Flutter Local variable for "serviceWorkerVersion" is deprecated
Asked Answered
M

4

6

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?

Melanous answered 17/5 at 0:0 Comment(0)
S
7
  1. Delete content under /web directory
  2. Run flutter create . --platforms=web to create a new index.html file, together with all the other files necessary

source: Upgrading an older project

Swung answered 14/6 at 20:53 Comment(3)
Works perfectly for Flutter 3.24.1.Ineducable
Works great. ill just add I had to do flutter clean and then flutter build web for it to stop showing this warning.Maintenon
This answer assumes your index.html doesn't have any custom information which isn't necessarily true. In my case I have customized this file for a custom splash screen and metadata tags.Ashes
M
3

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.

Melanous answered 17/5 at 0:10 Comment(0)
M
1

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.

Mournful answered 18/5 at 13:44 Comment(0)
L
-2

When building your Flutter app, the flutter build web command produces a script called flutter_bootstrap.js in the build output directory (build/web). This file contains the JavaScript code needed to initialize and run your Flutter app. You can use this script by placing an async-script tag for it in your index.html file in the web subdirectory of your Flutter app:

html
  body
    script src="flutter_bootstrap.js" async
  body
html

More detail here.

Lei answered 5/10 at 3:4 Comment(1)
Please edit your answer to style your markup as code so that it’s correctly displayed.Piliferous

© 2022 - 2024 — McMap. All rights reserved.