Skip to content

Commit

Permalink
Merge pull request #17 from swasan/feature/W-15331816
Browse files Browse the repository at this point in the history
@W-15331816 Update Android code to handle null values
  • Loading branch information
swasan authored and GitHub Enterprise committed Mar 26, 2024
2 parents eeb0353 + f7cbab6 commit fd5dcd9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?>("contactKey")?.let { contactKey ->
handleIdentityAction {
it.setProfileId(contactKey)
result.success(null)
}
} ?: result.error("INVALID_ARGUMENTS", "contactKey is null", null)
}

private fun getAttributes(result: Result) {
Expand All @@ -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<String?>("key")?.let { key ->
handleIdentityAction {
it.clearProfileAttribute(key)
result.success(null)
}
} ?: result.error("INVALID_ARGUMENTS", "clearAttribute key is null", null)
}

private fun getTags(result: Result) {
Expand All @@ -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<String?>("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<String?>("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) {
Expand Down
18 changes: 9 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class _MyAppState extends State<MyApp> {
}
}

void _onClarAttributesClicked(String key) {
void _onClearAttributesClicked(String key) {
try {
SFMCSdk.clearAttribute(key);
_showToast('Attribute cleared successfully!');
Expand Down Expand Up @@ -230,7 +230,7 @@ class _MyAppState extends State<MyApp> {
"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,
Expand All @@ -240,7 +240,7 @@ class _MyAppState extends State<MyApp> {
"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,
Expand All @@ -250,7 +250,7 @@ class _MyAppState extends State<MyApp> {
"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,
Expand Down Expand Up @@ -278,7 +278,7 @@ class _MyAppState extends State<MyApp> {
"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,
Expand All @@ -294,7 +294,7 @@ class _MyAppState extends State<MyApp> {
"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.',
Expand All @@ -316,7 +316,7 @@ class _MyAppState extends State<MyApp> {
"Get attributes from the SFMC SDK using SFMCSdk.getAttributes().",
() async {
await initPlatformState();
_showToast("Attributes Updated");
_showToast("Attributes Fetched");
},
'GET ATTRIBUTES',
content: _attributes.isNotEmpty
Expand All @@ -333,7 +333,7 @@ class _MyAppState extends State<MyApp> {
buildCardWithInput(
"Clear Attribute",
"Clear an attribute from the SFMC SDK using SFMCSdk.clearAttribute(key).",
_onClarAttributesClicked,
_onClearAttributesClicked,
'CLEAR ATTRIBUTE',
),
buildCard(
Expand All @@ -359,7 +359,7 @@ class _MyAppState extends State<MyApp> {
"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',
),
Expand Down

0 comments on commit fd5dcd9

Please sign in to comment.