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
:
dart
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:
dart
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:
yaml
flutter:
plugin:
platforms:
web:
pluginClass: HelloPlugin
fileName: hello_web.dart
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。