avoid_ web_ libraries_ in_ flutter
Learn about the avoid_web_libraries_in_flutter linter rule.
Avoid using web-only libraries outside Flutter web plugin packages.
Details
#
AVOID using web libraries,
dart:html, dart:js and
dart:js_util in Flutter packages that are not web
plugins. These libraries are not supported outside of a web
context; functionality that depends on them will fail at
runtime in Flutter mobile, and their use is generally
discouraged in Flutter web.
Web library access is allowed in:
-
plugin packages that declare
webas a supported context
otherwise, imports of dart:html,
dart:js and dart:js_util are
disallowed.
Enable
#
To enable the
avoid_web_libraries_in_flutter rule, add
avoid_web_libraries_in_flutter
under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- avoid_web_libraries_in_flutter
If you're instead using the YAML map syntax to configure
linter rules, add
avoid_web_libraries_in_flutter: true under
linter > rules:
linter:
rules:
avoid_web_libraries_in_flutter: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.