Wrapper around package:web that adds compatibility for non-web environments.
This package provides (non-functional) stubs for all interfaces and elements from web to allow being imported in cross-environment codebases (e.g. compiled to both web and native).
It is designed to be a drop-in replacement for package:web.
import 'package:universal_web/web.dart';
void main() {
// Make sure to only call the api when actually on web.
if (kIsWeb) {
final div = document.querySelector('div')!;
div.text = 'Text set at ${DateTime.now()}';
}
}The stubs are non-functional in non-web environments and should not be used (they will throw). The main purpose of this package is to allow being imported in other environments, not being used.
The package is generated from the same Web IDL definitions that web uses. It also uses the same versioning.
To migrate:
- change the dependency from
webtouniversal_web. - change all
package:web/web.dartimports topackage:universal_web/web.dart.