Skip to content

Commit e40167d

Browse files
authored
Bug fix for the DartError: TypeError: null: type 'Null' is not a subtype of type 'JSObject' (#1407)
* Bug fix for the DartError: TypeError: null: type 'Null' is not a subtype of type 'JSObject' when accessing the app via http where mediaDevices is not available. * Bug fix for the DartError: TypeError: null: type 'Null' is not a subtype of type 'JSObject' when accessing the app via http where mediaDevices is not available.
1 parent a0ded20 commit e40167d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

permission_handler_html/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.3+4
2+
3+
- http compatibility: Don't crash on missing `window.navigator.mediaDevices` property
4+
15
## 0.1.3+3
26

37
- Safari < 16 compatibility: Don't crash on missing `window.navigator.permissions` property

permission_handler_html/lib/permission_handler_html.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22
import 'dart:js_interop_unsafe';
3+
import 'dart:js_util' as js_util;
34

45
import 'package:web/web.dart' as web;
56

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

1213
/// Platform implementation of the permission_handler Flutter plugin.
1314
class WebPermissionHandler extends PermissionHandlerPlatform {
14-
static final web.MediaDevices _devices = web.window.navigator.mediaDevices;
15+
static final web.MediaDevices? _devices =
16+
js_util.hasProperty(web.window.navigator, 'mediaDevices')
17+
? js_util.getProperty(web.window.navigator, 'mediaDevices')
18+
: null;
1519
static final web.Geolocation _geolocation = web.window.navigator.geolocation;
1620
static final web.Permissions? _htmlPermissions = (() {
1721
// Using unsafe interop to check availability of `permissions`.

permission_handler_html/pubspec.yaml

Lines changed: 1 addition & 1 deletion
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+3
3+
version: 0.1.3+4
44

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

0 commit comments

Comments
 (0)