A collection of safe, zero-boilerplate helpers for browser DOM operations.
All methods are no-ops (or return sensible empty defaults) when called on
non-web platforms. On web, they delegate to package:web / dart:js_interop
so they work on both JS-compiled and WASM-compiled targets.
Event-stream getters return Stream<void> — they fire when the event
occurs but carry no event object. If you need the raw event data on web,
use package:web directly.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
Returns the raw cookie string (
document.cookie).no setter - documentTitle ↔ String
-
The browser tab/window title. Returns an empty string on non-web.
getter/setter pair
- isFullscreen → bool
-
Whether the page is currently in fullscreen mode. Returns
falseon non-web.no setter - isPageVisible → bool
-
Whether the page is currently visible. Returns
trueon non-web.no setter - locationHash ↔ String
-
The current URL hash fragment, e.g.
'#section'(with the leading#).getter/setter pair -
onBeforeUnload
→ Stream<
void> -
Stream of
beforeunloadevents. Returns an empty stream on non-web.no setter -
onContextMenu
→ Stream<
void> -
Stream that fires (with
null) whenever acontextmenuevent occurs on the document. Returns an empty stream on non-web.no setter -
onFullscreenChange
→ Stream<
void> -
Stream of fullscreen change events. Returns an empty stream on non-web.
no setter
-
onKeyDown
→ Stream<
void> -
Stream of
keydownevents on the window. Returns an empty stream on non-web.no setter -
onKeyPress
→ Stream<
void> -
Stream of
keypressevents on the window. Returns an empty stream on non-web.no setter -
onKeyUp
→ Stream<
void> -
Stream of
keyupevents on the window. Returns an empty stream on non-web.no setter -
onMouseDown
→ Stream<
void> -
Stream of
mousedownevents on the window. Returns an empty stream on non-web.no setter -
onMouseMove
→ Stream<
void> -
Stream of
mousemoveevents on the window. Returns an empty stream on non-web.no setter -
onMouseUp
→ Stream<
void> -
Stream of
mouseupevents on the window. Returns an empty stream on non-web.no setter -
onPopState
→ Stream<
void> -
Stream that fires when the user navigates browser history (
popstate).no setter -
onResize
→ Stream<
void> -
Stream of window resize events. Returns an empty stream on non-web.
no setter
-
onVisibilityChange
→ Stream<
void> -
Stream of
visibilitychangeevents. Returns an empty stream on non-web.no setter -
onWindowBlur
→ Stream<
void> -
Stream of window blur events. Returns an empty stream on non-web.
no setter
-
onWindowClick
→ Stream<
void> -
Stream of
clickevents on the window. Returns an empty stream on non-web.no setter -
onWindowFocus
→ Stream<
void> -
Stream of window focus events. Returns an empty stream on non-web.
no setter
-
urlParameters
→ Map<
String, String> -
Returns the query parameters of the current URL as a map.
no setter
- windowHeight → int
-
The viewport height in CSS pixels. Returns 0 on non-web.
no setter
- windowLocationHref → String
-
The current page's full URL (
window.location.href).no setter - windowWidth → int
-
The viewport width in CSS pixels. Returns 0 on non-web.
no setter
Static Methods
-
copyToClipboard(
String text) → Future< void> -
Copies
textto the system clipboard. Falls back silently on non-web or when the permission is denied. -
disableTextSelection(
) → void -
Disables text selection across the page via CSS
user-select: none. -
downloadBytesFile(
String filename, List< int> bytes, [String mimeType = 'application/octet-stream']) → void -
Triggers a browser file download with
filenameand rawbytes. -
downloadTextFile(
String filename, String content, [String mimeType = 'text/plain']) → void -
Triggers a browser file download with
filenameand textcontent. -
enableTextSelection(
) → void - Re-enables text selection across the page. No-op on non-web.
-
exitFullscreen(
) → Future< void> - Exits fullscreen mode. No-op on non-web.
-
getCookie(
String name) → String? -
Returns the value of the cookie with
name, ornullif not found. -
getCssVariable(
String name) → String? - Gets a CSS custom property value from the document root.
-
historyPushState(
Object? state, String title, String url) → void - Pushes a new entry onto the browser history stack. No-op on non-web.
-
historyReplaceState(
Object? state, String title, String url) → void - Replaces the current browser history entry. No-op on non-web.
-
Navigates the current tab to
url. No-op on non-web. -
openInNewTab(
String url) → void -
Opens
urlin a new tab. No-op on non-web. -
preventDefaultContextMenu(
) → void Function()? - Globally prevents the browser's native right-click context menu.
-
printPage(
) → void - Opens the browser's print dialog. No-op on non-web.
-
readFromClipboard(
) → Future< String> - Reads text from the system clipboard.
-
requestFullscreen(
) → Future< void> - Requests fullscreen for the document root element. No-op on non-web.
-
scrollBy(
int x, int y) → void - Scrolls the window by the given amounts. No-op on non-web.
-
scrollTo(
int x, int y) → void - Scrolls the window to the given position. No-op on non-web.
-
setCookie(
String name, String value, {DateTime? expires, String path = '/'}) → void - Sets a cookie. No-op on non-web.
-
setCssVariable(
String name, String value) → void -
Sets a CSS custom property on the document root (
--name: value). -
urlParameter(
String key) → String? -
Returns a single query parameter value by
key, ornullif absent. -
windowBlur(
) → void - Removes focus from the browser window. No-op on non-web.
-
windowFocus(
) → void - Brings the browser window to the foreground. No-op on non-web.
-
windowLocationReplace(
String url) → void -
Replaces the current browser history entry with
url. No-op on non-web. -
windowOpen(
String url, [String target = '_blank']) → void -
Opens
urlintarget(window.open(url, target)).