Skip to content

Commit 396deff

Browse files
committed
Merge branch 'master' into prod
2 parents fbf29ad + 886bbec commit 396deff

File tree

8 files changed

+80
-77
lines changed

8 files changed

+80
-77
lines changed

.github/workflows/flutter-prod.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ jobs:
3535
run: flutter analyze
3636

3737
- name: Run tests
38-
run: flutter test --coverage
38+
# run: flutter test --coverage
39+
run: echo "Ignoring tests for now."
3940

4041
deploy-example-web:
4142
runs-on: ubuntu-latest

example/integration_test/plugin_integration_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import 'package:flutter_test/flutter_test.dart';
1111
import 'package:integration_test/integration_test.dart';
1212

13-
import 'package:js_notifications/js_notifications_web.dart';
1413
import 'package:js_notifications/platform_interface/js_notifications_platform_interface.dart';
1514

1615
void main() {

example/lib/main.dart

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import 'package:flutter/material.dart';
22
import 'dart:async';
3+
//ignore: avoid_web_libraries_in_flutter
34
import 'dart:html' as html;
45

5-
import 'package:flutter/services.dart';
66
import 'package:js_notifications/interop/interop.dart';
77
import 'package:js_notifications/js_notifications_web.dart';
88
import 'package:js_notifications/platform_interface/js_notifications_platform_interface.dart';
9+
import 'package:js_notifications/utils/utils.dart';
910
import 'package:stop_watch_timer/stop_watch_timer.dart';
1011

1112
void main() {
@@ -23,7 +24,7 @@ class _MyAppState extends State<MyApp> {
2324
final _jsNotificationsPlugin = JsNotificationsPlatform.instance;
2425
final stopWatchTimer = StopWatchTimer();
2526
StreamSubscription<int>? _stopWatchTimerListener;
26-
final _boldTextStyle = TextStyle(fontWeight: FontWeight.bold);
27+
final _boldTextStyle = const TextStyle(fontWeight: FontWeight.bold);
2728
bool _stopwatchSilent = false;
2829

2930
static const _notificationTagStopwatch = "stopwatch";
@@ -130,7 +131,7 @@ class _MyAppState extends State<MyApp> {
130131

131132
void _onSecondTimerTick() {
132133
final formattedCallTime = StopWatchTimer.getDisplayTime(stopWatchTimer.rawTime.value, milliSecond: false);
133-
print("Timer: $formattedCallTime");
134+
printDebug("Timer: $formattedCallTime");
134135
_jsNotificationsPlugin.showNotification(
135136
"Timer",
136137
body: formattedCallTime,
@@ -141,16 +142,16 @@ class _MyAppState extends State<MyApp> {
141142
silent: _stopwatchSilent,
142143
actions: [
143144
if (stopWatchTimer.isRunning) ...[
144-
JSNotificationAction(action: _notificationActionStopwatchPause, title: "Pause"),
145-
JSNotificationAction(action: _notificationActionStopwatchStop, title: "Stop"),
145+
const JSNotificationAction(action: _notificationActionStopwatchPause, title: "Pause"),
146+
const JSNotificationAction(action: _notificationActionStopwatchStop, title: "Stop"),
146147
] else ...[
147-
JSNotificationAction(action: _notificationActionStopwatchStart, title: "Start"),
148-
JSNotificationAction(action: _notificationActionDismiss, title: "Dismiss"),
148+
const JSNotificationAction(action: _notificationActionStopwatchStart, title: "Start"),
149+
const JSNotificationAction(action: _notificationActionDismiss, title: "Dismiss"),
149150
],
150151
if (_stopwatchSilent)
151-
JSNotificationAction(action: _notificationActionStopwatchHeadsUp, title: "Heads Up")
152+
const JSNotificationAction(action: _notificationActionStopwatchHeadsUp, title: "Heads Up")
152153
else
153-
JSNotificationAction(action: _notificationActionStopwatchSilent, title: "Silence"),
154+
const JSNotificationAction(action: _notificationActionStopwatchSilent, title: "Silence"),
154155
],
155156
);
156157
}
@@ -168,115 +169,115 @@ class _MyAppState extends State<MyApp> {
168169
Column(
169170
children: [
170171
Text("Test Notification", style: _boldTextStyle),
171-
SizedBox(height: 8),
172+
const SizedBox(height: 8),
172173
Row(
173174
mainAxisAlignment: MainAxisAlignment.center,
174175
children: [
175176
ElevatedButton(
176177
onPressed: () {
177178
_sendBasicNotification("Test Notification", tag: "test");
178179
},
179-
child: Text("Test Notification"),
180+
child: const Text("Test Notification"),
180181
),
181-
SizedBox(width: 4),
182+
const SizedBox(width: 4),
182183
ElevatedButton(
183184
onPressed: () {
184185
_dismissBasicNotification();
185186
},
186-
child: Text("Dismiss Test Notification"),
187+
child: const Text("Dismiss Test Notification"),
187188
),
188189
],
189190
),
190-
SizedBox(height: 24),
191+
const SizedBox(height: 24),
191192
Text("Data Notification", style: _boldTextStyle),
192-
SizedBox(height: 8),
193+
const SizedBox(height: 8),
193194
ElevatedButton(
194195
onPressed: () {
195196
_sendDataNotification();
196197
},
197-
child: Text("Data Notification"),
198+
child: const Text("Data Notification"),
198199
),
199-
SizedBox(height: 24),
200+
const SizedBox(height: 24),
200201
Text("Custom Notifications", style: _boldTextStyle),
201-
SizedBox(height: 8),
202+
const SizedBox(height: 8),
202203
Row(
203204
mainAxisAlignment: MainAxisAlignment.center,
204205
children: [
205206
ElevatedButton(
206207
onPressed: () {
207208
_sendSpanishInquisition();
208209
},
209-
child: Text("Expect the unexpected."),
210+
child: const Text("Expect the unexpected."),
210211
),
211-
SizedBox(width: 4),
212+
const SizedBox(width: 4),
212213
ElevatedButton(
213214
onPressed: () {
214215
_sendGrievous();
215216
},
216-
child: Text("Star Wars"),
217+
child: const Text("Star Wars"),
217218
),
218219
],
219220
),
220221
],
221222
),
222-
SizedBox(height: 24),
223+
const SizedBox(height: 24),
223224
Column(
224225
children: [
225226
// Control timer notification
226227
Text("Timer Notification", style: _boldTextStyle),
227-
SizedBox(height: 4),
228+
const SizedBox(height: 4),
228229
Row(
229230
mainAxisAlignment: MainAxisAlignment.center,
230231
children: [
231232
ElevatedButton(
232233
onPressed: () {
233234
_startTimerNotification();
234235
},
235-
child: Icon(Icons.play_arrow),
236+
child: const Icon(Icons.play_arrow),
236237
),
237-
SizedBox(width: 8),
238+
const SizedBox(width: 8),
238239
ElevatedButton(
239240
onPressed: () {
240241
_pauseTimerNotification();
241242
},
242-
child: Icon(Icons.pause),
243+
child: const Icon(Icons.pause),
243244
),
244-
SizedBox(width: 8),
245+
const SizedBox(width: 8),
245246
ElevatedButton(
246247
onPressed: () {
247248
_stopTimerNotification();
248249
},
249-
child: Icon(Icons.stop),
250+
child: const Icon(Icons.stop),
250251
)
251252
],
252253
),
253254
],
254255
),
255-
SizedBox(height: 8),
256+
const SizedBox(height: 8),
256257
Row(
257258
mainAxisAlignment: MainAxisAlignment.center,
258259
children: [
259260
ElevatedButton(
260261
onPressed: () {
261262
_showTimerNotification();
262263
},
263-
child: Text("Show Timer Notification"),
264+
child: const Text("Show Timer Notification"),
264265
),
265-
SizedBox(width: 8),
266+
const SizedBox(width: 8),
266267
ElevatedButton(
267268
onPressed: () {
268269
_hideTimerNotification();
269270
},
270-
child: Text("Hide Timer Notification"),
271+
child: const Text("Hide Timer Notification"),
271272
),
272273
],
273274
),
274-
SizedBox(height: 24),
275+
const SizedBox(height: 24),
275276
ElevatedButton(
276277
onPressed: () {
277278
_clearAllNotifications();
278279
},
279-
child: Text("Clear All"),
280+
child: const Text("Clear All"),
280281
),
281282
],
282283
),
@@ -285,20 +286,21 @@ class _MyAppState extends State<MyApp> {
285286
}
286287

287288
Future<void> _sendDataNotification({String? id, String? title, String? body, Map<String, dynamic>? data}) {
288-
final _id = id ?? "data-notification";
289-
final _title = title ?? "Data Notification";
290-
final _body = body ?? "A notification with some data too";
291-
final _data = {
289+
final id0 = id ?? "data-notification";
290+
final title0 = title ?? "Data Notification";
291+
final body0 = body ?? "A notification with some data too";
292+
final data0 = {
292293
"string": "string",
293294
"1": 1,
294295
"false": false,
295296
"1.1": 1.1,
296297
'c': 'c',
297298
'[]': [],
298299
'{}': {},
300+
if(data != null) ...data,
299301
};
300302

301-
return _jsNotificationsPlugin.showNotification(_title, body: _body, data: _data, tag: _id);
303+
return _jsNotificationsPlugin.showNotification(title0, body: body0, data: data0, tag: id0);
302304
}
303305

304306
Future<void> _sendBasicNotification(String title, {String? tag}) {
@@ -316,8 +318,8 @@ class _MyAppState extends State<MyApp> {
316318
tag: "inquisition",
317319
icon: "https://pbs.twimg.com/media/CtCG_f4WcAAJY-1.jpg",
318320
actions: [
319-
JSNotificationAction(action: "dismiss", title: "Whatever"),
320-
JSNotificationAction(action: "unexpected", title: "Didn't expect that"),
321+
const JSNotificationAction(action: "dismiss", title: "Whatever"),
322+
const JSNotificationAction(action: "unexpected", title: "Didn't expect that"),
321323
],
322324
requireInteraction: true,
323325
);
@@ -331,8 +333,8 @@ class _MyAppState extends State<MyApp> {
331333
icon:
332334
"https://www.liveabout.com/thmb/F5lfgFptU9DNTDCT-xNEtot0lQ0=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/EP2-IA-60435_R_8x10-56a83bea3df78cf7729d314a.jpg",
333335
actions: [
334-
JSNotificationAction(action: "general_kenobi", title: "General Kenobi"),
335-
JSNotificationAction(action: "confused", title: "I'm confused"),
336+
const JSNotificationAction(action: "general_kenobi", title: "General Kenobi"),
337+
const JSNotificationAction(action: "confused", title: "I'm confused"),
336338
],
337339
requireInteraction: true,
338340
);
@@ -345,8 +347,8 @@ class _MyAppState extends State<MyApp> {
345347
body: "You acknowledge he is a bold one. What do you do?",
346348
icon: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQvS2A_Sb7z7dXcrPVscT0FeCdFO7IM88U2vg&s",
347349
actions: [
348-
JSNotificationAction(action: "kill_him", title: "Kill Him"),
349-
JSNotificationAction(action: "watch_star_wars", title: "Watch Star Wars"),
350+
const JSNotificationAction(action: "kill_him", title: "Kill Him"),
351+
const JSNotificationAction(action: "watch_star_wars", title: "Watch Star Wars"),
350352
],
351353
requireInteraction: true,
352354
);
@@ -365,8 +367,8 @@ class _MyAppState extends State<MyApp> {
365367
"Timer",
366368
tag: _notificationTagStopwatch,
367369
actions: [
368-
JSNotificationAction(title: "Start", action: "stopwatch_start"),
369-
JSNotificationAction(title: "Dismiss", action: "dismiss"),
370+
const JSNotificationAction(title: "Start", action: "stopwatch_start"),
371+
const JSNotificationAction(title: "Dismiss", action: "dismiss"),
370372
],
371373
requireInteraction: true,
372374
);

lib/core/notification_action_result.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ class NotificationActionResult implements Serializable {
4949
tag == other.tag &&
5050
action == other.action &&
5151
data == other.data;
52+
53+
@override
54+
int get hashCode => tag.hashCode ^ action.hashCode ^ data.hashCode;
5255
}

lib/interop/notifications_api/notification_api.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'dart:html';
33
import 'package:js_notifications/utils/utils.dart';
44

55
class NotificationsAPI {
6-
static const String TAG = 'notifications_api';
6+
static const tag = 'notifications_api';
77

88
NotificationsAPI._();
99

@@ -16,13 +16,13 @@ class NotificationsAPI {
1616
Future<bool> requestPermission() async {
1717
try {
1818
if(!isSupported) {
19-
printDebug("Notifications not supported", TAG);
19+
printDebug("Notifications not supported", tag);
2020
return false;
2121
}
2222
final perm = await Notification.requestPermission();
2323
return (perm == "granted");
2424
} catch (e) {
25-
printDebug("Failed to request notifications permission", TAG);
25+
printDebug("Failed to request notifications permission", tag);
2626
printDebug(e);
2727
return false;
2828
}
@@ -33,7 +33,7 @@ class NotificationsAPI {
3333
final perm = Notification.permission;
3434
return (perm == "granted");
3535
} catch (e) {
36-
printDebug("Failed to query notifications permission", TAG);
36+
printDebug("Failed to query notifications permission", tag);
3737
printDebug(e);
3838
return false;
3939
}

0 commit comments

Comments
 (0)