From a0a8aa2295de4c34961628c8e7cbd4afdcea78fb Mon Sep 17 00:00:00 2001 From: AR Abdul Azeez Date: Fri, 20 Nov 2026 10:14:09 -0600 Subject: [PATCH 1/2] fix: [SDK-5698] let initialize and login reach native Both guards returned before calling native. Initialize was the damaging one: native falls back to the cached app id, and short-circuiting skipped that fallback, leaving the SDK unstarted so the next login failed. Null is not a concern here. Dart null safety is on (sdk >=2.12.0) and both parameters are non-nullable String, so a Dart caller cannot pass null and isMissing could only ever catch an empty string. Native handles empty on both platforms: Android falls back to the cached app id after the never-crash change, and iOS initialize: rejects "" through OSInputGuard. The alias, email, SMS, tag, trigger, and outcome guards stay. Dropping the last isMissing call made the utils import unused; flutter analyze flagged it and it is removed. The test that asserted an empty externalId never reached the channel now asserts it is forwarded. DO NOT MERGE until oneSignalVersion in android/build.gradle can be bumped to a release containing the never-crash change. It pins 5.11.0, where an empty app id does not yet fall back to the cached one. Co-authored-by: Cursor --- lib/onesignal_flutter.dart | 3 --- test/onesignalflutter_test.dart | 13 ++++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/onesignal_flutter.dart b/lib/onesignal_flutter.dart index e33c3152..22107199 100644 --- a/lib/onesignal_flutter.dart +++ b/lib/onesignal_flutter.dart @@ -9,7 +9,6 @@ import 'package:onesignal_flutter/src/location.dart'; import 'package:onesignal_flutter/src/notifications.dart'; import 'package:onesignal_flutter/src/session.dart'; import 'package:onesignal_flutter/src/user.dart'; -import 'package:onesignal_flutter/src/utils.dart'; export 'src/defines.dart'; export 'src/inappmessage.dart'; @@ -49,7 +48,6 @@ class OneSignal { /// The initializer accepts an [appId] which the developer can get /// from the OneSignal consoleas well as a dictonary of [launchOptions] static Future initialize(String appId) async { - if (isMissing(appId, 'initialize: appId')) return; await _channel.invokeMethod('OneSignal#initialize', {'appId': appId}); await Future.wait([ InAppMessages.lifecycleInit(), @@ -64,7 +62,6 @@ class OneSignal { /// The act of logging a user into the OneSignal SDK will switch the /// user context to that specific user. static Future login(String externalId) async { - if (isMissing(externalId, 'login: externalId')) return; return await _channel.invokeMethod('OneSignal#login', { 'externalId': externalId, }); diff --git a/test/onesignalflutter_test.dart b/test/onesignalflutter_test.dart index 56a82d9d..c12aef9c 100644 --- a/test/onesignalflutter_test.dart +++ b/test/onesignalflutter_test.dart @@ -30,11 +30,14 @@ void main() { expect(channelController.state.externalId, equals('user-123')); }); - test('login rejects empty externalId', () async { - await OneSignal.login(''); - - expect(channelController.state.externalId, isNull); - }); + test( + 'login forwards an empty externalId to native, which ignores it', + () async { + await OneSignal.login(''); + + expect(channelController.state.externalId, equals('')); + }, + ); }); group('loginWithJWT', () { From 685a8ebb7b5190d2185d62256dbede477e653d88 Mon Sep 17 00:00:00 2001 From: AR Abdul Azeez Date: Fri, 20 Nov 2026 15:36:02 -0600 Subject: [PATCH 2/2] test: [SDK-5698] cover initialize('') and tighten a test name The suite had no case for an empty appId, so restoring the old guard would still have passed. The new test asserts '' is forwarded and that the lifecycle methods still run; reverting the guard turns it red. The login test name claimed native ignores the value when the test only checks forwarding, so it now says what it checks. Review feedback from fadi-george on #1205. Co-authored-by: Cursor --- test/onesignalflutter_test.dart | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/onesignalflutter_test.dart b/test/onesignalflutter_test.dart index c12aef9c..56ecb0d4 100644 --- a/test/onesignalflutter_test.dart +++ b/test/onesignalflutter_test.dart @@ -23,6 +23,17 @@ void main() { expect(channelController.state.userLifecycleInitCalled, isTrue); }); + test( + 'initialize forwards an empty appId and still runs lifecycle', + () async { + await OneSignal.initialize(''); + + expect(channelController.state.appId, equals('')); + expect(channelController.state.lifecycleInitCalled, isTrue); + expect(channelController.state.userLifecycleInitCalled, isTrue); + }, + ); + group('login', () { test('login invokes native method with externalId', () async { await OneSignal.login('user-123'); @@ -30,14 +41,11 @@ void main() { expect(channelController.state.externalId, equals('user-123')); }); - test( - 'login forwards an empty externalId to native, which ignores it', - () async { - await OneSignal.login(''); + test('login forwards an empty externalId to native', () async { + await OneSignal.login(''); - expect(channelController.state.externalId, equals('')); - }, - ); + expect(channelController.state.externalId, equals('')); + }); }); group('loginWithJWT', () {