diff --git a/packages/flutter_tools/lib/src/html_utils.dart b/packages/flutter_tools/lib/src/html_utils.dart index 259f038739..ad394aaa90 100644 --- a/packages/flutter_tools/lib/src/html_utils.dart +++ b/packages/flutter_tools/lib/src/html_utils.dart @@ -70,8 +70,9 @@ class IndexHtml { if (serviceWorkerVersion != null) { _content = _content .replaceFirst( - 'var serviceWorkerVersion = null', - 'var serviceWorkerVersion = "$serviceWorkerVersion"', + // Support older `var` syntax as well as new `const` syntax + RegExp('(const|var) serviceWorkerVersion = null'), + 'const serviceWorkerVersion = "$serviceWorkerVersion"', ) // This is for legacy index.html that still uses the old service // worker loading mechanism. diff --git a/packages/flutter_tools/templates/app_shared/web/index.html.tmpl b/packages/flutter_tools/templates/app_shared/web/index.html.tmpl index 6d9aa4d08c..2e1847c4a7 100644 --- a/packages/flutter_tools/templates/app_shared/web/index.html.tmpl +++ b/packages/flutter_tools/templates/app_shared/web/index.html.tmpl @@ -34,7 +34,7 @@ diff --git a/packages/flutter_tools/test/general.shard/html_utils_test.dart b/packages/flutter_tools/test/general.shard/html_utils_test.dart index b8c10525ca..83a5f0c1a6 100644 --- a/packages/flutter_tools/test/general.shard/html_utils_test.dart +++ b/packages/flutter_tools/test/general.shard/html_utils_test.dart @@ -31,6 +31,28 @@ const String htmlSample2 = ''' +
+ + + + + +