Open gonciuu opened 1 year ago
getting the same error
flutter 3.7.11 platform ios 16 package version 1.1.1
bumping this @fbenevides
Getting the same error, it looks that if the auth succeed the platform handles it incorrectly at the callback handling. If I am attempting to send notification to the user after this error the notification received susccessfully.
I believe the reason for this error is this code:
@override
void handleCallback(String callbackId, String callbackName, List args) {
final callback = _callbacks[callbackId]!;
switch (callbackName) {
case "onInterestChanges":
callback((args[0] as List<Object?>).cast<String>());
return;
case "setUserId":
callback(args[0] as String?);
return;
case "onMessageReceivedInTheForeground":
callback((args[0] as Map<Object?, Object?>));
return;
default:
callback();
return;
}
}
for setUserId when there is no error there is an attempt to access args[0] in callback(args[0] as String?) but the args are empty so we get Array range error. Since the callback params setUesrId should be not empty only if error is happened the list being empty is an expected behavior for success. The code should probably change to something like this:
callback(args.isEmpty ? null : args[0] as String?);
Getting the same error, it looks that if the auth succeed the platform handles it incorrectly at the callback handling. If I am attempting to send notification to the user after this error the notification received susccessfully.
I believe the reason for this error is this code:
@override void handleCallback(String callbackId, String callbackName, List args) { final callback = _callbacks[callbackId]!; switch (callbackName) { case "onInterestChanges": callback((args[0] as List<Object?>).cast<String>()); return; case "setUserId": callback(args[0] as String?); return; case "onMessageReceivedInTheForeground": callback((args[0] as Map<Object?, Object?>)); return; default: callback(); return; } }
for setUserId when there is no error there is an attempt to access args[0] in callback(args[0] as String?) but the args are empty so we get Array range error. Since the callback params setUesrId should be not empty only if error is happened the list being empty is an expected behavior for success. The code should probably change to something like this:
callback(args.isEmpty ? null : args[0] as String?);
Should be a simple enough fix, perhaps if the main devs don't have time to implement it, someone could open a PR to fix it?
Hi, I'd like to merge https://github.com/pusher/push-notifications-flutter/pull/44, but I'd also like to reproduce the original issue. When I call setUserId(), it authorizes fine for me without throwing RangeError. I'm testing on Android however, are you using iOS or web browser target?
@benjamin-tang-pusher I'm using iOS, it seems to be the only platform affected (to my knowledge, I've tested android and iOS, but not web).
@benjamin-tang-pusher I was testing this on iOS simulator and real iOS device like half year ago and this Error occurs only on iOS (I've also tested android and everything worked fine).
Just run into this today, still an issue on iOS using simulator or real device. The setUserid
function doesn't return any args on iOS when successfully authenticating, causing the array index bug in the handleCallback
function @anyab5 and others mentioned. Trying not to maintain my own local fork if possible :) Any news on merging @CoolDude53's PR? Thanks.
When I use the following method:
Everything works as expected - the notifications are consistently received. However, an error appears in the console:
I have attempted to find a solution, but it seems to be an issue with the library itself.