dart analyze flags dart:html and package:js as deprecated in a Flutter web or Dart web project
Your error
info - 'dart:html' is deprecated and shouldn't be used. Use package:web and dart:js_interop instead. - deprecated_member_use3 more lines it can showFix it fast
Most common cause, 1 of 4DOM code imports dart:html
Add package:web and import it with a prefix to avoid name clashes.
dart pub add web
import 'package:web/web.dart' as web;
void main() {
final el = web.document.querySelector('#status') as web.HTMLElement?;
el?.textContent = 'ready';
el?.onClick.listen((web.MouseEvent e) {});
web.window.localStorage.setItem('k', 'v');
}Short answer
The Dart analyzer now marks dart:html, and package:js, as deprecated because they cannot compile to WebAssembly. Their replacements are package:web for DOM and browser APIs and dart:js_interop for calling JavaScript. Add web to pubspec.yaml, import it with a prefix, swap @JS declarations to dart:js_interop, and change conditional imports from dart.library.html to dart.library.js_interop.
Which cause do you have?
List every file that still uses the old libraries, and check which of your dependencies pull in the discontinued js package.
grep -rlnE "dart:html|dart:js_util|dart:js'|package:js/" lib test
dart pub deps --style=compact | grep -E "^- js |js "Then find the line you see in this list and open its fix:
- 1DOM code imports dart:html
The deprecated_member_use info sits on an import 'dart:html' line - 2JavaScript calls use package:js or dart:js_util
The info names package:js/js.dart, and dart pub get lists js as discontinued - 3Conditional imports test for dart.library.html
An export or import uses if (dart.library.html) to choose the web implementation - 4Code relies on is checks against DOM types
After the switch, a test like event.target is InputElement never matches or behaves differently
What does the error look like?
info - 'dart:html' is deprecated and shouldn't be used. Use package:web and dart:js_interop instead. - deprecated_member_useinfo - 'package:js/js.dart' is deprecated and shouldn't be used. Use dart:js_interop instead. - deprecated_member_use+ js 0.7.2 (discontinued)1 package is discontinued.
Cause 1 of 4
DOM code imports dart:html
You seeThe deprecated_member_use info sits on an import 'dart:html' line
Check
Dart's migration guide calls dart:html and the other core web libraries deprecated and unsupported for Wasm. package:web exposes the same browser APIs with names taken from the Web IDL, so HTMLElement replaces Element and so on.
grep -rn "import 'dart:html'" libFix
Add package:web and import it with a prefix to avoid name clashes. Casts to the exact HTML type are often needed after querySelector.
dart pub add web
import 'package:web/web.dart' as web;
void main() {
final el = web.document.querySelector('#status') as web.HTMLElement?;
el?.textContent = 'ready';
el?.onClick.listen((web.MouseEvent e) {});
web.window.localStorage.setItem('k', 'v');
}Verify
dart analyze reports no deprecated_member_use on the file.
dart analyze libConfirmed by dart.dev
Cause 2 of 4
JavaScript calls use package:js or dart:js_util
You seeThe info names package:js/js.dart, and dart pub get lists js as discontinued
Check
The old @JS annotation from package:js and the helpers in dart:js_util are replaced by static interop in dart:js_interop, which works for both the JavaScript and the Wasm compilers.
grep -rnE "package:js/|dart:js_util" libFix
Declare the JavaScript function with the @JS annotation from dart:js_interop and pass JS types, converting Dart values with toJS. Then remove js from pubspec.yaml.
import 'dart:js_interop';
@JS('console.log')
external void consoleLog(JSString message);
void ping() => consoleLog('clicked'.toJS);Verify
After removing js from pubspec.yaml, pub get no longer reports a discontinued package from your own dependencies and analyze is clean.
dart pub get && dart analyzeConfirmed by dart.dev
Cause 3 of 4
Conditional imports test for dart.library.html
You seeAn export or import uses if (dart.library.html) to choose the web implementation
Check
That condition depends on the deprecated library. The migration guide says to tell web from native with dart.library.js_interop instead, which is also true for Wasm builds.
grep -rn "dart.library.html" libFix
Switch the condition and point it at a file written with package:web.
export 'src/storage_stub.dart'
if (dart.library.io) 'src/storage_io.dart'
if (dart.library.js_interop) 'src/storage_web.dart';Verify
flutter build web, and flutter build web --wasm if you target Wasm, both compile.
flutter build web --wasmConfirmed by dart.dev
Cause 4 of 4
Code relies on is checks against DOM types
You seeAfter the switch, a test like event.target is InputElement never matches or behaves differently
Check
package:web types are all JSObject at runtime, so an is check cannot tell an input from a div. The guide replaces such tests with isA or instanceOfString.
grep -rnE " is (Html|Input|Anchor|Div)\w*Element" libFix
Use the typed helper from dart:js_interop.
import 'dart:js_interop';
import 'package:web/web.dart' as web;
bool isTextInput(web.EventTarget? t) => t != null && t.isA<web.HTMLInputElement>();Verify
Exercise the branch in a browser run; the check now returns true for the right element only.
flutter run -d chromeConfirmed by dart.dev
How do I stop it coming back?
- Write new web code against package:web from the first line.
- Turn on the Wasm build in CI; it fails fast on anything that still needs dart:html.
- Check pub get output for discontinued packages after each dependency update.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.