Skip to content

Lightweight browser API bindings built around JS static interop.

License

Notifications You must be signed in to change notification settings

schultek/universal_web

 
 

Repository files navigation

Dart CI pub package package publisher

Wrapper around package:web that adds compatibility for non-web environments.

What's this?

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.

Usage

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.

Migrate

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 web to universal_web.
  • change all package:web/web.dart imports to package:universal_web/web.dart.

About

Lightweight browser API bindings built around JS static interop.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages

  • Dart 99.9%
  • Other 0.1%