Skip to content
pubscout

universal_web

1.1.1+2, released 6 weeks ago by schultek.dev

Wrapper that allows importing web APIs in non-web environments

WASM-ready
$ flutter pub add universal_web
Source repository

What it does

It provides non-functional stubs for all interfaces from package:web so that code can be compiled for web and native. The stubs can be imported but will throw if used on non-web platforms.

AI-written summary of version 1.1.1+2, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to share code that imports web APIs across web and native targets
  • You want a drop‑in replacement for package:web during development

Skip it when

  • You actually need to execute web APIs on a non-web platform
  • You want to avoid runtime errors from stubs

Strengths

  • Easy to add as a dependency
  • No build_runner or code generation required
  • Zero runtime cost on non-web

Weaknesses

  • Stubs are non-functional and will throw if called on non-web
  • Only useful for import compatibility, not for actual functionality

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1
import 'package:universal_web/web.dart';

void main() {
  if (kIsWeb) {
    final div = document.querySelector('div')!;
    div.text = 'Text set at ${DateTime.now()}';
  }
}

Alternatives

Packages that do the same job and could replace universal_web.

  • adb

    A Dart wrapper for interacting with the Android Debug Bridge (adb).

  • serial

    Wrapper for the Web Serial API to use serial ports in Flutter web.

  • actors

    Thin wrapper around Dart Isolates implementing the Actor Model

  • wasm_interop

    Dart wrapper for the WebAssembly JavaScript API.

Works with

Packages commonly used together with universal_web: ones it builds on, ones built on it, and its own family.