webxr 0.1.0 copy "webxr: ^0.1.0" to clipboard
webxr: ^0.1.0 copied to clipboard

Platformweb

Dart bindings for WebXR APIs.

WebXR #

Dart bindings for the WebXR APIs.

Overview #

WebXR provides Dart bindings for the WebXR Device API, enabling developers to create immersive virtual reality (VR) and augmented reality (AR) experiences using Dart and web technologies.

Installation #

Add this package to your pubspec.yaml:

dependencies:
  webxr: ^0.1.0

Then run:

dart pub get

Usage #

Basic Example #

 import 'dart:js_interop';

import 'package:web/web.dart' as web;
import 'package:webxr/webxr.dart';

void main() async {
  final body = web.document.body;

  if (body == null) {
    print('Body element not found');
    return;
  }

  body.append(web.document.createElement('div')..textContent = 'WebXR Example');

  final navigator = Navigator.$(web.window.navigator);
  final xr = navigator.xr;

  if (xr == null) {
    print('WebXR is not supported in this browser');
    return;
  }

  try {
    final vrSupported = await xr.isSessionSupported('immersive-vr'.toJS).toDart;
    body.append(web.document.createElement('div')
      ..textContent = 'Immersive VR supported: $vrSupported');

    final arSupported = await xr.isSessionSupported('immersive-ar'.toJS).toDart;
    body.append(web.document.createElement('div')
      ..textContent = 'Immersive AR supported: $arSupported');

    final inlineSupported = await xr.isSessionSupported('inline'.toJS).toDart;
    body.append(web.document.createElement('div')
      ..textContent = 'Inline mode supported: $inlineSupported');
  } catch (e) {
    body.append(web.document.createElement('div')
      ..textContent = 'Error checking WebXR support: $e');
  }
}

Development #

This package provides type-safe Dart bindings for the WebXR APIs. The bindings are designed to work with Dart's dart:js_interop library for seamless JavaScript integration.

How the package is created #

The bindings are generated using the packages

  • ts-ast-export: Generates a representation of a TypeScript definition file in JSON format.
  • ts_interop: Creates Dart bindings from the JSON file.

Both packages are work in progress.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Support #

Changelog #

See CHANGELOG.md for a detailed history of changes.

0
likes
140
points
42
downloads

Publisher

verified publisherblimster.net

Weekly Downloads

Dart bindings for WebXR APIs.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

es2023, web

More

Packages that depend on webxr