Skip to content

Commit

Permalink
fix: don't crash on safari<16 (#1383)
Browse files Browse the repository at this point in the history
* fix: don't crash on safari<16

* fix: apply PR Pre-launch Checklist
  • Loading branch information
holzgeist authored Oct 8, 2024
1 parent 416e7b0 commit 4e840ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions permission_handler_html/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.3+3

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

## 0.1.3+2

- `web: 1.0.0` compatibility: `PermissionDescriptor` was removed in web package.
Expand Down
12 changes: 10 additions & 2 deletions permission_handler_html/lib/permission_handler_html.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:js_interop_unsafe';

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

Expand All @@ -12,8 +13,15 @@ import 'web_delegate.dart';
class WebPermissionHandler extends PermissionHandlerPlatform {
static final web.MediaDevices _devices = web.window.navigator.mediaDevices;
static final web.Geolocation _geolocation = web.window.navigator.geolocation;
static final web.Permissions _htmlPermissions =
web.window.navigator.permissions;
static final web.Permissions? _htmlPermissions = (() {
// Using unsafe interop to check availability of `permissions`.
// It's not defined as nullable, so merely loading it into a web.Permission? variable
// causes the null-check to fail
if (!web.window.navigator.has("permissions")) {
return null;
}
return web.window.navigator.permissions;
})();

final WebDelegate _webDelegate;

Expand Down
2 changes: 1 addition & 1 deletion permission_handler_html/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: permission_handler_html
description: Permission plugin for Flutter. This plugin provides the web API to request and check permissions.
version: 0.1.3+2
version: 0.1.3+3

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

Expand Down

0 comments on commit 4e840ae

Please sign in to comment.