avoid_web_libraries_in_flutter
Don't use web-only libraries outside Flutter web plugins.
Description
#The analyzer produces this diagnostic when a library in a package that isn't a web plugin contains an import of a web-only library:
dart:html
dart:js
dart:js_util
dart:js_interop
dart:js_interop_unsafe
package:js
package:web
Example
#When found in a package that isn't a web plugin, the following code produces this diagnostic because it imports dart:html
:
import 'dart:html';
import 'package:flutter/material.dart';
class C {}
Common fixes
#If the package isn't intended to be a web plugin, then remove the import:
import 'package:flutter/material.dart';
class C {}
If the package is intended to be a web plugin, then add the following lines to the pubspec.yaml
file of the package:
flutter:
plugin:
platforms:
web:
pluginClass: HelloPlugin
fileName: hello_web.dart
See Developing packages & plugins for more information.
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.