1
- import 'package:flutter/material.dart' ;
2
1
import 'dart:async' ;
3
2
//ignore: avoid_web_libraries_in_flutter
4
3
import 'dart:html' as html;
5
4
5
+ import 'package:flutter/foundation.dart' ;
6
+ import 'package:flutter/material.dart' ;
6
7
import 'package:js_notifications/interop/interop.dart' ;
7
8
import 'package:js_notifications/js_notifications_web.dart' ;
8
9
import 'package:js_notifications/platform_interface/js_notifications_platform_interface.dart' ;
9
- import 'package:js_notifications/utils/utils.dart' ;
10
10
import 'package:stop_watch_timer/stop_watch_timer.dart' ;
11
11
12
12
void main () {
@@ -61,77 +61,94 @@ class _MyAppState extends State<MyApp> {
61
61
}
62
62
case "confused" :
63
63
{
64
- _sendBasicNotification ("Go watch Star Wars, now!" , tag: "star_wars_channel" );
64
+ _sendBasicNotification ("Go watch Star Wars, now!" ,
65
+ tag: "star_wars_channel" );
65
66
break ;
66
67
}
67
68
case "kill_him" :
68
69
{
69
- _sendBasicNotification ("Good good, now go watch Star Wars!" , tag: "star_wars_channel" );
70
+ _sendBasicNotification ("Good good, now go watch Star Wars!" ,
71
+ tag: "star_wars_channel" );
70
72
break ;
71
73
}
72
74
case "watch_star_wars" :
73
75
{
74
- _sendBasicNotification ("Sure, click here to watch it." , tag: "rick_roll" );
76
+ _sendBasicNotification ("Sure, click here to watch it." ,
77
+ tag: "rick_roll" );
75
78
break ;
76
79
}
77
80
78
- case _notificationActionStopwatchStart: {
79
- _startTimerNotification ();
80
- break ;
81
- }
81
+ case _notificationActionStopwatchStart:
82
+ {
83
+ _startTimerNotification ();
84
+ break ;
85
+ }
82
86
83
- case _notificationActionStopwatchPause: {
84
- _pauseTimerNotification ();
85
- _onSecondTimerTick ();
86
- break ;
87
- }
87
+ case _notificationActionStopwatchPause:
88
+ {
89
+ _pauseTimerNotification ();
90
+ _onSecondTimerTick ();
91
+ break ;
92
+ }
88
93
89
- case _notificationActionStopwatchStop: {
90
- _stopTimerNotification ();
91
- _onSecondTimerTick ();
92
- break ;
93
- }
94
+ case _notificationActionStopwatchStop:
95
+ {
96
+ _stopTimerNotification ();
97
+ _onSecondTimerTick ();
98
+ break ;
99
+ }
94
100
95
- case _notificationActionStopwatchSilent: {
96
- setState (() {
97
- _stopwatchSilent = true ;
98
- });
99
- break ;
100
- }
101
+ case _notificationActionStopwatchSilent:
102
+ {
103
+ setState (() {
104
+ _stopwatchSilent = true ;
105
+ });
106
+ break ;
107
+ }
101
108
102
- case _notificationActionStopwatchHeadsUp: {
103
- setState (() {
104
- _stopwatchSilent = false ;
105
- });
106
- break ;
107
- }
109
+ case _notificationActionStopwatchHeadsUp:
110
+ {
111
+ setState (() {
112
+ _stopwatchSilent = false ;
113
+ });
114
+ break ;
115
+ }
108
116
109
- default : {
110
- if (event.tag == "rick_roll" ) {
111
- openNewWindow ("https://www.youtube.com/watch?v=dQw4w9WgXcQ" );
112
- } else if (event.tag == "star_wars_channel" ) {
113
- openNewWindow ("https://www.youtube.com/@StarWars" );
117
+ default :
118
+ {
119
+ if (event.tag == "rick_roll" ) {
120
+ openNewWindow ("https://www.youtube.com/watch?v=dQw4w9WgXcQ" );
121
+ } else if (event.tag == "star_wars_channel" ) {
122
+ openNewWindow ("https://www.youtube.com/@StarWars" );
123
+ }
114
124
}
115
- }
116
125
}
117
126
});
118
127
_jsNotificationsPlugin.dismissStream.listen ((event) {
119
- switch (event.tag) {
120
- case "data-notification" : {
121
- _sendBasicNotification ("Dismissed data notification" , tag: "" );
122
- break ;
123
- }
124
- case "grievous" : {
125
- _sendBasicNotification ("My disappointment is immeasurable and my day is ruined." , tag: "ruined" );
126
- break ;
127
- }
128
+ switch (event.tag) {
129
+ case "data-notification" :
130
+ {
131
+ _sendBasicNotification ("Dismissed data notification" , tag: "" );
132
+ break ;
133
+ }
134
+ case "grievous" :
135
+ {
136
+ _sendBasicNotification (
137
+ "My disappointment is immeasurable and my day is ruined." ,
138
+ tag: "ruined" );
139
+ break ;
140
+ }
128
141
}
129
142
});
130
143
}
131
144
132
145
void _onSecondTimerTick () {
133
- final formattedCallTime = StopWatchTimer .getDisplayTime (stopWatchTimer.rawTime.value, milliSecond: false );
134
- printDebug ("Timer: $formattedCallTime " );
146
+ final formattedCallTime = StopWatchTimer .getDisplayTime (
147
+ stopWatchTimer.rawTime.value,
148
+ milliSecond: false );
149
+ if (kDebugMode) {
150
+ print ("Timer: $formattedCallTime " );
151
+ }
135
152
_jsNotificationsPlugin.showNotification (
136
153
"Timer" ,
137
154
body: formattedCallTime,
@@ -142,16 +159,22 @@ class _MyAppState extends State<MyApp> {
142
159
silent: _stopwatchSilent,
143
160
actions: [
144
161
if (stopWatchTimer.isRunning) ...[
145
- const JSNotificationAction (action: _notificationActionStopwatchPause, title: "Pause" ),
146
- const JSNotificationAction (action: _notificationActionStopwatchStop, title: "Stop" ),
162
+ const JSNotificationAction (
163
+ action: _notificationActionStopwatchPause, title: "Pause" ),
164
+ const JSNotificationAction (
165
+ action: _notificationActionStopwatchStop, title: "Stop" ),
147
166
] else ...[
148
- const JSNotificationAction (action: _notificationActionStopwatchStart, title: "Start" ),
149
- const JSNotificationAction (action: _notificationActionDismiss, title: "Dismiss" ),
167
+ const JSNotificationAction (
168
+ action: _notificationActionStopwatchStart, title: "Start" ),
169
+ const JSNotificationAction (
170
+ action: _notificationActionDismiss, title: "Dismiss" ),
150
171
],
151
172
if (_stopwatchSilent)
152
- const JSNotificationAction (action: _notificationActionStopwatchHeadsUp, title: "Heads Up" )
173
+ const JSNotificationAction (
174
+ action: _notificationActionStopwatchHeadsUp, title: "Heads Up" )
153
175
else
154
- const JSNotificationAction (action: _notificationActionStopwatchSilent, title: "Silence" ),
176
+ const JSNotificationAction (
177
+ action: _notificationActionStopwatchSilent, title: "Silence" ),
155
178
],
156
179
);
157
180
}
@@ -175,7 +198,8 @@ class _MyAppState extends State<MyApp> {
175
198
children: [
176
199
ElevatedButton (
177
200
onPressed: () {
178
- _sendBasicNotification ("Test Notification" , tag: "test" );
201
+ _sendBasicNotification ("Test Notification" ,
202
+ tag: "test" );
179
203
},
180
204
child: const Text ("Test Notification" ),
181
205
),
@@ -285,7 +309,8 @@ class _MyAppState extends State<MyApp> {
285
309
);
286
310
}
287
311
288
- Future <void > _sendDataNotification ({String ? id, String ? title, String ? body, Map <String , dynamic >? data}) {
312
+ Future <void > _sendDataNotification (
313
+ {String ? id, String ? title, String ? body, Map <String , dynamic >? data}) {
289
314
final id0 = id ?? "data-notification" ;
290
315
final title0 = title ?? "Data Notification" ;
291
316
final body0 = body ?? "A notification with some data too" ;
@@ -297,10 +322,11 @@ class _MyAppState extends State<MyApp> {
297
322
'c' : 'c' ,
298
323
'[]' : [],
299
324
'{}' : {},
300
- if (data != null ) ...data,
325
+ if (data != null ) ...data,
301
326
};
302
327
303
- return _jsNotificationsPlugin.showNotification (title0, body: body0, data: data0, tag: id0);
328
+ return _jsNotificationsPlugin.showNotification (title0,
329
+ body: body0, data: data0, tag: id0);
304
330
}
305
331
306
332
Future <void > _sendBasicNotification (String title, {String ? tag}) {
@@ -314,12 +340,14 @@ class _MyAppState extends State<MyApp> {
314
340
Future <void > _sendSpanishInquisition () {
315
341
return _jsNotificationsPlugin.showNotification (
316
342
"Oh no!" ,
317
- body: "Subverted expectations result in expected unexpected expectations. Anyway, check the icon..." ,
343
+ body:
344
+ "Subverted expectations result in expected unexpected expectations. Anyway, check the icon..." ,
318
345
tag: "inquisition" ,
319
346
icon: "https://pbs.twimg.com/media/CtCG_f4WcAAJY-1.jpg" ,
320
347
actions: [
321
348
const JSNotificationAction (action: "dismiss" , title: "Whatever" ),
322
- const JSNotificationAction (action: "unexpected" , title: "Didn't expect that" ),
349
+ const JSNotificationAction (
350
+ action: "unexpected" , title: "Didn't expect that" ),
323
351
],
324
352
requireInteraction: true ,
325
353
);
@@ -333,7 +361,8 @@ class _MyAppState extends State<MyApp> {
333
361
icon:
334
362
"https://www.liveabout.com/thmb/F5lfgFptU9DNTDCT-xNEtot0lQ0=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/EP2-IA-60435_R_8x10-56a83bea3df78cf7729d314a.jpg" ,
335
363
actions: [
336
- const JSNotificationAction (action: "general_kenobi" , title: "General Kenobi" ),
364
+ const JSNotificationAction (
365
+ action: "general_kenobi" , title: "General Kenobi" ),
337
366
const JSNotificationAction (action: "confused" , title: "I'm confused" ),
338
367
],
339
368
requireInteraction: true ,
@@ -345,10 +374,12 @@ class _MyAppState extends State<MyApp> {
345
374
"Grievous" ,
346
375
tag: "grievous_2" ,
347
376
body: "You acknowledge he is a bold one. What do you do?" ,
348
- icon: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQvS2A_Sb7z7dXcrPVscT0FeCdFO7IM88U2vg&s" ,
377
+ icon:
378
+ "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQvS2A_Sb7z7dXcrPVscT0FeCdFO7IM88U2vg&s" ,
349
379
actions: [
350
380
const JSNotificationAction (action: "kill_him" , title: "Kill Him" ),
351
- const JSNotificationAction (action: "watch_star_wars" , title: "Watch Star Wars" ),
381
+ const JSNotificationAction (
382
+ action: "watch_star_wars" , title: "Watch Star Wars" ),
352
383
],
353
384
requireInteraction: true ,
354
385
);
@@ -375,7 +406,8 @@ class _MyAppState extends State<MyApp> {
375
406
}
376
407
377
408
void _startTimerNotification () {
378
- _stopWatchTimerListener ?? = stopWatchTimer.secondTime.listen ((_) => _onSecondTimerTick ());
409
+ _stopWatchTimerListener ?? =
410
+ stopWatchTimer.secondTime.listen ((_) => _onSecondTimerTick ());
379
411
_stopwatchSilent = false ;
380
412
stopWatchTimer.onStartTimer ();
381
413
}
0 commit comments