Avoid using web-only libraries outside Flutter web plugin packages Avoid using web-only libraries outside Flutter web plugin packages dart dart

Avoid using web-only libraries outside Flutter web plugin packages


Use the universal_html package. It supports the browser, Dart VM, and Flutter and is a stand-in replacement for dart:html and other web related libraries.

dependencies:  universal_html: ^1.2.1

Then instead of using import 'dart:html' as html; you can use the following import:

import 'package:universal_html/html.dart' as html;

For those who came to this page for other related web import problems (like dart:js), this plugin also supports the following imports:

import 'package:universal_html/driver.dart';import 'package:universal_html/html.dart';import 'package:universal_html/indexed_db.dart';import 'package:universal_html/js.dart';import 'package:universal_html/js_util.dart';import 'package:universal_html/prefer_sdk/html.dart';import 'package:universal_html/prefer_sdk/indexed_db.dart';import 'package:universal_html/prefer_sdk/js.dart';import 'package:universal_html/prefer_sdk/js_util.dart';import 'package:universal_html/prefer_sdk/svg.dart';import 'package:universal_html/prefer_sdk/web_gl.dart';import 'package:universal_html/prefer_universal/html.dart';import 'package:universal_html/prefer_universal/indexed_db.dart';import 'package:universal_html/prefer_universal/js.dart';import 'package:universal_html/prefer_universal/js_util.dart';import 'package:universal_html/prefer_universal/svg.dart';import 'package:universal_html/prefer_universal/web_gl.dart';import 'package:universal_html/svg.dart';import 'package:universal_html/web_gl.dart';