diff --git a/android/src/main/kotlin/com/salesforce/marketingcloud/sfmc/SfmcPlugin.kt b/android/src/main/kotlin/com/salesforce/marketingcloud/sfmc/SfmcPlugin.kt index b16e32b..b73d80f 100644 --- a/android/src/main/kotlin/com/salesforce/marketingcloud/sfmc/SfmcPlugin.kt +++ b/android/src/main/kotlin/com/salesforce/marketingcloud/sfmc/SfmcPlugin.kt @@ -164,11 +164,12 @@ class SfmcPlugin : FlutterPlugin, MethodCallHandler { } private fun setContactKey(call: MethodCall, result: Result) { - val contactKey: String? = call.argument("contactKey") - handleIdentityAction { - it.setProfileId(contactKey ?: "") - result.success(null) - } + call.argument("contactKey")?.let { contactKey -> + handleIdentityAction { + it.setProfileId(contactKey) + result.success(null) + } + } ?: result.error("INVALID_ARGUMENTS", "contactKey is null", null) } private fun getAttributes(result: Result) { @@ -181,18 +182,21 @@ class SfmcPlugin : FlutterPlugin, MethodCallHandler { private fun setAttribute(call: MethodCall, result: Result) { val key: String? = call.argument("key") val value: String? = call.argument("value") - handleIdentityAction { - it.setProfileAttribute(key ?: "", value ?: "") - result.success(null) - } + key?.let { key -> + handleIdentityAction { + it.setProfileAttribute(key, value) + result.success(null) + } + } ?: result.error("INVALID_ARGUMENTS", "attribute key is null", null) } private fun clearAttribute(call: MethodCall, result: Result) { - val key: String? = call.argument("key") - handleIdentityAction { - it.clearProfileAttribute(key ?: "") - result.success(null) - } + call.argument("key")?.let { key -> + handleIdentityAction { + it.clearProfileAttribute(key) + result.success(null) + } + } ?: result.error("INVALID_ARGUMENTS", "clearAttribute key is null", null) } private fun getTags(result: Result) { @@ -203,19 +207,21 @@ class SfmcPlugin : FlutterPlugin, MethodCallHandler { } private fun addTag(call: MethodCall, result: Result) { - val tag: String? = call.argument("tag") - handlePushAction { - it.registrationManager.edit().addTag(tag ?: "").commit() - result.success(null) - } + call.argument("tag")?.let { tag -> + handlePushAction { + it.registrationManager.edit().addTag(tag).commit() + result.success(null) + } + } ?: result.error("INVALID_ARGUMENTS", "tag is null", null) } private fun removeTag(call: MethodCall, result: Result) { - val tag: String? = call.argument("tag") - handlePushAction { - it.registrationManager.edit().removeTag(tag ?: "").commit() - result.success(null) - } + call.argument("tag")?.let { tag -> + handlePushAction { + it.registrationManager.edit().removeTag(tag).commit() + result.success(null) + } + } ?: result.error("INVALID_ARGUMENTS", "tag is null", null) } private fun trackEvent(call: MethodCall, result: Result) { diff --git a/example/lib/main.dart b/example/lib/main.dart index 3d6bf82..4bf199f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -141,7 +141,7 @@ class _MyAppState extends State { } } - void _onClarAttributesClicked(String key) { + void _onClearAttributesClicked(String key) { try { SFMCSdk.clearAttribute(key); _showToast('Attribute cleared successfully!'); @@ -230,7 +230,7 @@ class _MyAppState extends State { "Get the system token from the SFMC SDK using SFMCSdk.getSystemToken().", () async { await initPlatformState(); - _showToast("System Token Updated"); + _showToast("System Token Fetched"); }, 'GET SYSTEM TOKEN', content: _systemToken, @@ -240,7 +240,7 @@ class _MyAppState extends State { "Get the device ID from the SFMC SDK using SFMCSdk.getDeviceId().", () async { await initPlatformState(); - _showToast("Device ID Updated"); + _showToast("Device ID Fetched"); }, 'GET DEVICE ID', content: _deviceId, @@ -250,7 +250,7 @@ class _MyAppState extends State { "Check if push notifications are enabled or disabled using SFMCSdk.isPushEnabled().", () async { await initPlatformState(); - _showToast("Push Status Updated"); + _showToast("Push Status Fetched"); }, 'UPDATE PUSH STATUS', content: _pushStatus, @@ -278,7 +278,7 @@ class _MyAppState extends State { "Get the contact key from the SFMC SDK using SFMCSdk.getContactKey().", () async { await initPlatformState(); - _showToast("Contact Key Updated"); + _showToast("Contact Key Fetched"); }, 'GET CONTACT KEY', content: _contactKey, @@ -294,7 +294,7 @@ class _MyAppState extends State { "Get tags from the SFMC SDK using SFMCSdk.getTags().", () async { await initPlatformState(); - _showToast("Tags Updated"); + _showToast("Tags Fetched"); }, 'GET TAGS', content: _tags.isNotEmpty ? _tags.join(', ') : 'No tags found.', @@ -316,7 +316,7 @@ class _MyAppState extends State { "Get attributes from the SFMC SDK using SFMCSdk.getAttributes().", () async { await initPlatformState(); - _showToast("Attributes Updated"); + _showToast("Attributes Fetched"); }, 'GET ATTRIBUTES', content: _attributes.isNotEmpty @@ -333,7 +333,7 @@ class _MyAppState extends State { buildCardWithInput( "Clear Attribute", "Clear an attribute from the SFMC SDK using SFMCSdk.clearAttribute(key).", - _onClarAttributesClicked, + _onClearAttributesClicked, 'CLEAR ATTRIBUTE', ), buildCard( @@ -359,7 +359,7 @@ class _MyAppState extends State { "Log the state of the SFMC SDK using SFMCSdk.logSdkState().", () { SFMCSdk.logSdkState(); - _showToast("SDK state logged."); + _showToast("Check platform logs for SDK state."); }, 'LOG SDK STATE', ),