dart-lang / html

Dart port of html5lib. For parsing HTML/HTML5 with Dart. Works in the client and on the server.
https://pub.dev/packages/html
Other
276 stars 58 forks source link

PushManager.getSubscription() errors on null #226

Open mrwonko opened 11 months ago

mrwonko commented 11 months ago

PushManager.getSubscription is defined as Future<PushSubscription>, but if there's no subscription, it actually returns null, leading to an Error:

Error: Expected a value of type 'FutureOr', but got one of type 'Null'

According to https://developer.mozilla.org/en-US/docs/Web/API/PushManager/getSubscription, this is expected, and I don't see how else I'd check whether a subscription has been configured yet.

Can be reproduced with

await (await html.window.navigator.serviceWorker?.ready)?.pushManager?.getSubscription();