universal_web
1.1.1+2, released 6 weeks ago by schultek.dev
Wrapper that allows importing web APIs in non-web environments
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).
77Compare - serial
Wrapper for the Web Serial API to use serial ports in Flutter web.
48Compare - actors
Thin wrapper around Dart Isolates implementing the Actor Model
44Compare - wasm_interop
Dart wrapper for the WebAssembly JavaScript API.
41Compare
Works with
Packages commonly used together with universal_web: ones it builds on, ones built on it, and its own family.
- webuniversal_web depends on itLightweight bindings for browser APIs via JS interop
- jasprBuilt on universal_webA web framework for building websites in Dart with Flutter-like syntax and server-side rendering.
- jaspr_contentBuilt on universal_webJaspr plugin for building content-driven sites like documentation and blogs.
- spotBuilt on universal_webToolkit for Flutter widget tests with chainable selectors and automatic timeline reports.
- flint_dartBuilt on universal_webFull‑stack Dart framework for building server, UI, and APIs in pure Dart
- naki_uiBuilt on universal_webMaterial-inspired UI components and design utilities for building responsive web apps with Jaspr.
- deepyrBuilt on universal_webType‑safe Dart implementation of daisyUI components for Jaspr, using a fluent API.