Skip to content

Commit 5dfbf5e

Browse files
Get rid of unused imports
Fixes issues raised by the analyzer similar t: * info • Unused import: 'package:flutter/foundation.dart' • lib/src/create_notification.dart:2:8 • unused_import info • The import of 'package:onesignal_flutter/src/notification.dart' is unnecessary because all of the used elements are also provided by the import of * 'package:onesignal_flutter/onesignal_flutter.dart' • lib/src/create_notification.dart:3:8 • unnecessary_import
1 parent b89d95b commit 5dfbf5e

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

lib/src/create_notification.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import 'package:onesignal_flutter/src/utils.dart';
2-
import 'package:flutter/foundation.dart';
3-
import 'package:onesignal_flutter/src/notification.dart';
42
import 'package:onesignal_flutter/onesignal_flutter.dart';
53

64
/// The parameters & format to create push notifications is

lib/src/notification.dart

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import 'package:onesignal_flutter/src/defines.dart';
21
import 'package:onesignal_flutter/src/utils.dart';
32
import 'package:onesignal_flutter/onesignal_flutter.dart';
4-
import 'package:flutter/foundation.dart';
53
import 'dart:convert';
64

75
/// A class representing the notification, including the
86
/// payload of the notification as well as additional
97
/// parameters (such as whether the notification was `shown`
108
/// to the user, whether it's `silent`, etc.)
119
class OSNotification extends JSONStringRepresentable {
12-
1310
/// The OneSignal notification ID for this notification
1411
late String notificationId;
1512

@@ -188,8 +185,7 @@ class OSNotification extends JSONStringRepresentable {
188185
this.mutableContent = json['mutableContent'] as bool?;
189186
if (json.containsKey('category'))
190187
this.category = json['category'] as String?;
191-
if (json.containsKey('badge'))
192-
this.badge = json['badge'] as int?;
188+
if (json.containsKey('badge')) this.badge = json['badge'] as int?;
193189
if (json.containsKey('badgeIncrement'))
194190
this.badgeIncrement = json['badgeIncrement'] as int?;
195191
if (json.containsKey('subtitle'))
@@ -222,8 +218,7 @@ class OSNotification extends JSONStringRepresentable {
222218
this.fromProjectNumber = json['fromProjectNumber'] as String?;
223219
if (json.containsKey("collapseId"))
224220
this.collapseId = json['collapseId'] as String?;
225-
if (json.containsKey("priority"))
226-
this.priority = json['priority'] as int?;
221+
if (json.containsKey("priority")) this.priority = json['priority'] as int?;
227222
if (json.containsKey("androidNotificationId"))
228223
this.androidNotificationId = json['androidNotificationId'] as int?;
229224
if (json.containsKey('backgroundImageLayout')) {
@@ -232,24 +227,23 @@ class OSNotification extends JSONStringRepresentable {
232227
}
233228
if (json.containsKey('groupedNotifications')) {
234229
final dynamic jsonGroupedNotifications = json['groupedNotifications'];
235-
final jsonList = jsonDecode(jsonGroupedNotifications.toString()) as List<dynamic>;
236-
this.groupedNotifications = jsonList.map((dynamic item) =>
237-
OSNotification(item as Map<String, dynamic>)).toList();
230+
final jsonList =
231+
jsonDecode(jsonGroupedNotifications.toString()) as List<dynamic>;
232+
this.groupedNotifications = jsonList
233+
.map((dynamic item) => OSNotification(item as Map<String, dynamic>))
234+
.toList();
238235
}
239-
236+
240237
// shared parameters
241238
this.notificationId = json['notificationId'] as String;
242239

243240
if (json.containsKey('templateName'))
244241
this.templateName = json['templateName'] as String?;
245242
if (json.containsKey('templateId'))
246243
this.templateId = json['templateId'] as String?;
247-
if (json.containsKey('sound'))
248-
this.sound = json['sound'] as String?;
249-
if (json.containsKey('title'))
250-
this.title = json['title'] as String?;
251-
if (json.containsKey('body'))
252-
this.body = json['body'] as String?;
244+
if (json.containsKey('sound')) this.sound = json['sound'] as String?;
245+
if (json.containsKey('title')) this.title = json['title'] as String?;
246+
if (json.containsKey('body')) this.body = json['body'] as String?;
253247
if (json.containsKey('launchUrl'))
254248
this.launchUrl = json['launchUrl'] as String?;
255249
if (json.containsKey('additionalData'))
@@ -382,25 +376,25 @@ class OSAndroidBackgroundImageLayout extends JSONStringRepresentable {
382376
}
383377

384378
class OSNotificationReceivedEvent extends JSONStringRepresentable {
385-
386379
late OSNotification notification;
387380

388381
OSNotificationReceivedEvent(Map<String, dynamic> json) {
389382
notification = OSNotification(json);
390383
}
391384

392385
void complete(OSNotification? notification) {
393-
print('OSNotificationReceivedEvent complete with notification: $notification');
386+
print(
387+
'OSNotificationReceivedEvent complete with notification: $notification');
394388
if (notification != null) {
395-
OneSignal.shared.completeNotification(notification.notificationId, true);
389+
OneSignal.shared.completeNotification(notification.notificationId, true);
396390
} else {
397-
OneSignal.shared.completeNotification(this.notification.notificationId, false);
391+
OneSignal.shared
392+
.completeNotification(this.notification.notificationId, false);
398393
}
399394
}
400395

401396
String jsonRepresentation() {
402-
return convertToJsonString({
403-
'notification': this.notification.jsonRepresentation()
404-
});
397+
return convertToJsonString(
398+
{'notification': this.notification.jsonRepresentation()});
405399
}
406-
}
400+
}

test/mock_channel.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:async';
21
import 'package:flutter/services.dart';
32
import 'package:onesignal_flutter/onesignal_flutter.dart';
43
import 'package:flutter_test/flutter_test.dart';
@@ -63,14 +62,16 @@ class OneSignalMockChannelController {
6362
this.state.deleteTags = call.arguments;
6463
return {"success": true};
6564
case "OneSignal#setExternalUserId":
66-
this.state.externalId = (call.arguments as Map<dynamic, dynamic>)['externalUserId'] as String?;
67-
return {"success" : true};
65+
this.state.externalId = (call.arguments
66+
as Map<dynamic, dynamic>)['externalUserId'] as String?;
67+
return {"success": true};
6868
case "OneSignal#removeExternalUserId":
6969
this.state.externalId = null;
70-
return {"success" : true};
70+
return {"success": true};
7171
case "OneSignal#setLanguage":
72-
this.state.language = (call.arguments as Map<dynamic, dynamic>)['language'] as String?;
73-
return {"success" : true};
72+
this.state.language =
73+
(call.arguments as Map<dynamic, dynamic>)['language'] as String?;
74+
return {"success": true};
7475
}
7576
}
7677
}

test/notification_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import 'package:test/test.dart';
22
import 'package:onesignal_flutter/src/notification.dart';
3-
import 'package:onesignal_flutter/src/defines.dart';
43
import 'test_data.dart';
54

65
void main() {
76
final notificationJson = TestData.jsonForTest('notification_parsing_test');
87
final notification = OSNotification(notificationJson);
98

109
test('expect notification ID to be set', () {
11-
expect(notification.notificationId,
12-
"8e0eeec2-aa42-4ff7-a74b-bce9ca9e588b");
10+
expect(notification.notificationId, "8e0eeec2-aa42-4ff7-a74b-bce9ca9e588b");
1311
});
1412

1513
test('expect buttons to be parsed correctly', () {

0 commit comments

Comments
 (0)