Skip to content

Commit b89d95b

Browse files
Use isEmpty property instead of checking for null
This addresses issues found in the analyzer similar to: info • The operand can't be null, so the condition is always false • example/lib/main.dart:130:16 • unnecessary_null_comparison
1 parent 5972213 commit b89d95b

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

example/lib/main.dart

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class _MyAppState extends State<MyApp> {
5656
_debugLabelString =
5757
"Notification received in foreground notification: \n${event.notification.jsonRepresentation().replaceAll("\\n", "\n")}";
5858
});
59-
});
59+
});
6060

6161
OneSignal.shared
6262
.setInAppMessageClickedHandler((OSInAppMessageAction action) {
63-
this.setState(() {
63+
this.setState(() {
6464
_debugLabelString =
6565
"In App Message Clicked: \n${action.jsonRepresentation().replaceAll("\\n", "\n")}";
6666
});
@@ -80,8 +80,8 @@ class _MyAppState extends State<MyApp> {
8080
print("EMAIL SUBSCRIPTION STATE CHANGED ${changes.jsonRepresentation()}");
8181
});
8282

83-
OneSignal.shared.setSMSSubscriptionObserver(
84-
(OSSMSSubscriptionStateChanges changes) {
83+
OneSignal.shared
84+
.setSMSSubscriptionObserver((OSSMSSubscriptionStateChanges changes) {
8585
print("SMS SUBSCRIPTION STATE CHANGED ${changes.jsonRepresentation()}");
8686
});
8787

@@ -102,8 +102,7 @@ class _MyAppState extends State<MyApp> {
102102
});
103103

104104
// NOTE: Replace with your own app ID from https://www.onesignal.com
105-
await OneSignal.shared
106-
.setAppId("380dc082-5231-4cc2-ab51-a03da5a0e4c2");
105+
await OneSignal.shared.setAppId("380dc082-5231-4cc2-ab51-a03da5a0e4c2");
107106

108107
// iOS-only method to open launch URLs in Safari when set to false
109108
OneSignal.shared.setLaunchURLsInApp(false);
@@ -122,13 +121,14 @@ class _MyAppState extends State<MyApp> {
122121
// Some examples of how to use Outcome Events public methods with OneSignal SDK
123122
oneSignalOutcomeEventsExamples();
124123

125-
bool userProvidedPrivacyConsent = await OneSignal.shared.userProvidedPrivacyConsent();
124+
bool userProvidedPrivacyConsent =
125+
await OneSignal.shared.userProvidedPrivacyConsent();
126126
print("USER PROVIDED PRIVACY CONSENT: $userProvidedPrivacyConsent");
127127
}
128128

129129
void _handleGetTags() {
130130
OneSignal.shared.getTags().then((tags) {
131-
if (tags == null) return;
131+
if (tags.isEmpty) return;
132132

133133
setState((() {
134134
_debugLabelString = "$tags";
@@ -169,7 +169,8 @@ class _MyAppState extends State<MyApp> {
169169
OneSignal.shared.getDeviceState().then((deviceState) {
170170
print("DeviceState: ${deviceState?.jsonRepresentation()}");
171171
this.setState(() {
172-
_debugLabelString = deviceState?.jsonRepresentation() ?? "Device state null";
172+
_debugLabelString =
173+
deviceState?.jsonRepresentation() ?? "Device state null";
173174
});
174175
});
175176
}
@@ -208,7 +209,7 @@ class _MyAppState extends State<MyApp> {
208209
});
209210
}
210211

211-
void _handleSetSMSNumber() {
212+
void _handleSetSMSNumber() {
212213
if (_smsNumber == null) return;
213214

214215
print("Setting SMS Number");
@@ -266,29 +267,28 @@ class _MyAppState extends State<MyApp> {
266267
if (_externalUserId == null) return;
267268

268269
OneSignal.shared.setExternalUserId(_externalUserId!).then((results) {
269-
if (results == null) return;
270+
if (results.isEmpty) return;
270271

271-
this.setState(() {
272-
_debugLabelString = "External user id set: $results";
273-
});
272+
this.setState(() {
273+
_debugLabelString = "External user id set: $results";
274+
});
274275
});
275276
}
276277

277278
void _handleRemoveExternalUserId() {
278279
OneSignal.shared.removeExternalUserId().then((results) {
279-
if (results == null) return;
280+
if (results.isEmpty) return;
280281

281-
this.setState(() {
282-
_debugLabelString = "External user id removed: $results";
283-
});
282+
this.setState(() {
283+
_debugLabelString = "External user id removed: $results";
284+
});
284285
});
285286
}
286287

287288
void _handleSendNotification() async {
288289
var deviceState = await OneSignal.shared.getDeviceState();
289290

290-
if (deviceState == null || deviceState.userId == null)
291-
return;
291+
if (deviceState == null || deviceState.userId == null) return;
292292

293293
var playerId = deviceState.userId!;
294294

@@ -316,8 +316,7 @@ class _MyAppState extends State<MyApp> {
316316
void _handleSendSilentNotification() async {
317317
var deviceState = await OneSignal.shared.getDeviceState();
318318

319-
if (deviceState == null || deviceState.userId == null)
320-
return;
319+
if (deviceState == null || deviceState.userId == null) return;
321320

322321
var playerId = deviceState.userId!;
323322

@@ -350,7 +349,8 @@ class _MyAppState extends State<MyApp> {
350349
OneSignal.shared.removeTriggerForKey("trigger_2");
351350

352351
// Get the value for a trigger by its key
353-
Object? triggerValue = await OneSignal.shared.getTriggerValueForKey("trigger_3");
352+
Object? triggerValue =
353+
await OneSignal.shared.getTriggerValueForKey("trigger_3");
354354
print("'trigger_3' key trigger value: ${triggerValue?.toString()}");
355355

356356
// Create a list and bulk remove triggers based on keys supplied
@@ -385,8 +385,8 @@ class _MyAppState extends State<MyApp> {
385385
}
386386

387387
Future<void> outcomeAwaitExample() async {
388-
var outcomeEvent = await OneSignal.shared.sendOutcome("await_normal_1");
389-
print(outcomeEvent.jsonRepresentation());
388+
var outcomeEvent = await OneSignal.shared.sendOutcome("await_normal_1");
389+
print(outcomeEvent.jsonRepresentation());
390390
}
391391

392392
@override
@@ -415,10 +415,8 @@ class _MyAppState extends State<MyApp> {
415415
_handlePromptForPushPermission, !_enableConsentButton)
416416
]),
417417
new TableRow(children: [
418-
new OneSignalButton(
419-
"Print Device State",
420-
_handleGetDeviceState,
421-
!_enableConsentButton)
418+
new OneSignalButton("Print Device State",
419+
_handleGetDeviceState, !_enableConsentButton)
422420
]),
423421
new TableRow(children: [
424422
new TextField(
@@ -469,12 +467,12 @@ class _MyAppState extends State<MyApp> {
469467
)
470468
]),
471469
new TableRow(children: [
472-
new OneSignalButton(
473-
"Set SMS Number", _handleSetSMSNumber, !_enableConsentButton)
470+
new OneSignalButton("Set SMS Number", _handleSetSMSNumber,
471+
!_enableConsentButton)
474472
]),
475473
new TableRow(children: [
476-
new OneSignalButton("Logout SMS Number", _handleLogoutSMSNumber,
477-
!_enableConsentButton)
474+
new OneSignalButton("Logout SMS Number",
475+
_handleLogoutSMSNumber, !_enableConsentButton)
478476
]),
479477
new TableRow(children: [
480478
new OneSignalButton("Provide GDPR Consent", _handleConsent,
@@ -517,12 +515,12 @@ class _MyAppState extends State<MyApp> {
517515
)
518516
]),
519517
new TableRow(children: [
520-
new OneSignalButton(
521-
"Set External User ID", _handleSetExternalUserId, !_enableConsentButton)
518+
new OneSignalButton("Set External User ID",
519+
_handleSetExternalUserId, !_enableConsentButton)
522520
]),
523521
new TableRow(children: [
524-
new OneSignalButton(
525-
"Remove External User ID", _handleRemoveExternalUserId, !_enableConsentButton)
522+
new OneSignalButton("Remove External User ID",
523+
_handleRemoveExternalUserId, !_enableConsentButton)
526524
]),
527525
new TableRow(children: [
528526
new TextField(
@@ -545,8 +543,8 @@ class _MyAppState extends State<MyApp> {
545543
)
546544
]),
547545
new TableRow(children: [
548-
new OneSignalButton(
549-
"Set Language", _handleSetLanguage, !_enableConsentButton)
546+
new OneSignalButton("Set Language", _handleSetLanguage,
547+
!_enableConsentButton)
550548
]),
551549
new TableRow(children: [
552550
new Container(

0 commit comments

Comments
 (0)