Skip to content

Commit cb27a13

Browse files
authored
Bug fix for WASM compilation (#1411)
1 parent 11d3baa commit cb27a13

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

permission_handler_html/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.3+5
2+
3+
- wasm compatibility: Changed way how `window.navigator.mediaDevices` is accessed
4+
15
## 0.1.3+4
26

37
- Fixes a bug causing the application to crash when running on HTTP protocol (not HTTPS or localhost) and the `window.navigator.mediaDevices` property is `null`.

permission_handler_html/lib/permission_handler_html.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
22
import 'dart:js_interop_unsafe';
3-
import 'dart:js_util' as js_util;
43

54
import 'package:web/web.dart' as web;
65

@@ -12,10 +11,12 @@ import 'web_delegate.dart';
1211

1312
/// Platform implementation of the permission_handler Flutter plugin.
1413
class WebPermissionHandler extends PermissionHandlerPlatform {
15-
static final web.MediaDevices? _devices =
16-
js_util.hasProperty(web.window.navigator, 'mediaDevices')
17-
? js_util.getProperty(web.window.navigator, 'mediaDevices')
18-
: null;
14+
static final web.MediaDevices? _devices = (() {
15+
if (!web.window.navigator.has('mediaDevices')) {
16+
return null;
17+
}
18+
return web.window.navigator.mediaDevices;
19+
})();
1920
static final web.Geolocation _geolocation = web.window.navigator.geolocation;
2021
static final web.Permissions? _htmlPermissions = (() {
2122
// Using unsafe interop to check availability of `permissions`.

permission_handler_html/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: permission_handler_html
22
description: Permission plugin for Flutter. This plugin provides the web API to request and check permissions.
3-
version: 0.1.3+4
3+
version: 0.1.3+5
44

55
homepage: https://github.com/baseflow/flutter-permission-handler
66

0 commit comments

Comments
 (0)