Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pendingNotificationRequests returning null instead of a List on iOS #1287

Closed
corcoran opened this issue Aug 17, 2021 · 11 comments
Closed

pendingNotificationRequests returning null instead of a List on iOS #1287

corcoran opened this issue Aug 17, 2021 · 11 comments

Comments

@corcoran
Copy link

Describe the bug
Some iOS users are experiencing an error when pendingNotificationRequests() is called.

type 'Null' is not a subtype of type 'int'. Error thrown null.
  pendingNotificationRequests.<fn> + 62 (platform_flutter_local_notifications.dart:62)
  toList (dart:collection)
  pendingNotificationRequests + 63 (platform_flutter_local_notifications.dart:63)

To Reproduce
Unclear how to reproduce, only seems to occur since upgrading to null safety. iOS 12-14 users, iPhone and iPad.

Expected behavior
pendingNotificationRequests() should return a list, not throw an exception

Sample code to reproduce the problem
FlutterLocalNotificationsPlugin().pendingNotificationRequests()

@lucasribolli
Copy link
Contributor

Does that issue occurs only in real devices or in both device and simulator?

@corcoran
Copy link
Author

Have only seen this on real devices, haven't been able to reproduce it ourselves.

@corcoran corcoran changed the title pendingNotificationRequests returning null instead of id on iOS pendingNotificationRequests returning null instead of a List on iOS Aug 19, 2021
@MaikuB
Copy link
Owner

MaikuB commented Aug 20, 2021

I'd need ways to reproduce a bug in order to investigate them. I suspect that you have other code that is scheduling notifications that is causing the problem and null safety has only surfaced up an existing problem.

If so, you'd need to address this within your own app as you need to vet libraries you use to see if they achieve what you're after or if you need to implement your own native code. More specifically, the old iOS notification API doesn't expose the notification id as a standard field to be read when looking at pending notifications. It is something this plugin needed to put in as custom info (see https://developer.apple.com/documentation/uikit/uilocalnotification/1616657-userinfo) and is specific to this plugin

@corcoran
Copy link
Author

I definitely agree that you should be able to reproduce it and I'll try to find a way to do that.

That said, the inability of this library to return a list of pendingNotificationRequests() (regardless of where they were created), should be marked as a bug. Maybe the solution is to make the int id field nullable to account for such a case?

@MaikuB
Copy link
Owner

MaikuB commented Aug 23, 2021

What would be the use case here and what is the use case you have in your own app at the moment?

@MaikuB
Copy link
Owner

MaikuB commented Oct 22, 2021

As there's been no further response on how to reproduce this and my last question on the use case, this issue will be closed. Feel free to reopen if more info can be provided

@MaikuB MaikuB closed this as completed Oct 22, 2021
@harryandroiddev
Copy link

same issue on ios

@harryandroiddev
Copy link

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'int'
#0 MethodChannelFlutterLocalNotificationsPlugin.pendingNotificationRequests.
package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:81
#1 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#2 ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#3 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#4 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#5 new List.of (dart:core-patch/array_patch.dart:51:28)
#6 ListIterable.toList (dart:_internal/iterable.dart:213:44)
#7 MethodChannelFlutterLocalNotificationsPlugin.pendingNotificationRequests
package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:82

@harryandroiddev
Copy link

it should not return null , rather than empty list .

@marcotta
Copy link

In my case I am testing upgrading an existing native iOS app with a new flutter app.
The native app scheduled some notifications and those come without an id.

When the flutter app is installed, calling pendingNotificationRequests retrieves those created from previous app and
throws type 'Null' is not a subtype of type 'int'.

Perhaps id should be nullable as it is not so uncommon to rewrite an existing native app in flutter.
@MaikuB what do you think?

but yes I can workaround it, with a try/catch and cancelAll() in the catch

@qwadrox
Copy link

qwadrox commented Dec 18, 2023

In my case I am testing upgrading an existing native iOS app with a new flutter app. The native app scheduled some notifications and those come without an id.

When the flutter app is installed, calling pendingNotificationRequests retrieves those created from previous app and throws type 'Null' is not a subtype of type 'int'.

Perhaps id should be nullable as it is not so uncommon to rewrite an existing native app in flutter. @MaikuB what do you think?

but yes I can workaround it, with a try/catch and cancelAll() in the catch

This might be our issue. Switched from Xamarin lately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants