1
1
import 'package:flutter/material.dart' ;
2
2
import 'dart:async' ;
3
+ //ignore: avoid_web_libraries_in_flutter
3
4
import 'dart:html' as html;
4
5
5
- import 'package:flutter/services.dart' ;
6
6
import 'package:js_notifications/interop/interop.dart' ;
7
7
import 'package:js_notifications/js_notifications_web.dart' ;
8
8
import 'package:js_notifications/platform_interface/js_notifications_platform_interface.dart' ;
9
+ import 'package:js_notifications/utils/utils.dart' ;
9
10
import 'package:stop_watch_timer/stop_watch_timer.dart' ;
10
11
11
12
void main () {
@@ -23,7 +24,7 @@ class _MyAppState extends State<MyApp> {
23
24
final _jsNotificationsPlugin = JsNotificationsPlatform .instance;
24
25
final stopWatchTimer = StopWatchTimer ();
25
26
StreamSubscription <int >? _stopWatchTimerListener;
26
- final _boldTextStyle = TextStyle (fontWeight: FontWeight .bold);
27
+ final _boldTextStyle = const TextStyle (fontWeight: FontWeight .bold);
27
28
bool _stopwatchSilent = false ;
28
29
29
30
static const _notificationTagStopwatch = "stopwatch" ;
@@ -130,7 +131,7 @@ class _MyAppState extends State<MyApp> {
130
131
131
132
void _onSecondTimerTick () {
132
133
final formattedCallTime = StopWatchTimer .getDisplayTime (stopWatchTimer.rawTime.value, milliSecond: false );
133
- print ("Timer: $formattedCallTime " );
134
+ printDebug ("Timer: $formattedCallTime " );
134
135
_jsNotificationsPlugin.showNotification (
135
136
"Timer" ,
136
137
body: formattedCallTime,
@@ -141,16 +142,16 @@ class _MyAppState extends State<MyApp> {
141
142
silent: _stopwatchSilent,
142
143
actions: [
143
144
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" ),
146
147
] 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" ),
149
150
],
150
151
if (_stopwatchSilent)
151
- JSNotificationAction (action: _notificationActionStopwatchHeadsUp, title: "Heads Up" )
152
+ const JSNotificationAction (action: _notificationActionStopwatchHeadsUp, title: "Heads Up" )
152
153
else
153
- JSNotificationAction (action: _notificationActionStopwatchSilent, title: "Silence" ),
154
+ const JSNotificationAction (action: _notificationActionStopwatchSilent, title: "Silence" ),
154
155
],
155
156
);
156
157
}
@@ -168,115 +169,115 @@ class _MyAppState extends State<MyApp> {
168
169
Column (
169
170
children: [
170
171
Text ("Test Notification" , style: _boldTextStyle),
171
- SizedBox (height: 8 ),
172
+ const SizedBox (height: 8 ),
172
173
Row (
173
174
mainAxisAlignment: MainAxisAlignment .center,
174
175
children: [
175
176
ElevatedButton (
176
177
onPressed: () {
177
178
_sendBasicNotification ("Test Notification" , tag: "test" );
178
179
},
179
- child: Text ("Test Notification" ),
180
+ child: const Text ("Test Notification" ),
180
181
),
181
- SizedBox (width: 4 ),
182
+ const SizedBox (width: 4 ),
182
183
ElevatedButton (
183
184
onPressed: () {
184
185
_dismissBasicNotification ();
185
186
},
186
- child: Text ("Dismiss Test Notification" ),
187
+ child: const Text ("Dismiss Test Notification" ),
187
188
),
188
189
],
189
190
),
190
- SizedBox (height: 24 ),
191
+ const SizedBox (height: 24 ),
191
192
Text ("Data Notification" , style: _boldTextStyle),
192
- SizedBox (height: 8 ),
193
+ const SizedBox (height: 8 ),
193
194
ElevatedButton (
194
195
onPressed: () {
195
196
_sendDataNotification ();
196
197
},
197
- child: Text ("Data Notification" ),
198
+ child: const Text ("Data Notification" ),
198
199
),
199
- SizedBox (height: 24 ),
200
+ const SizedBox (height: 24 ),
200
201
Text ("Custom Notifications" , style: _boldTextStyle),
201
- SizedBox (height: 8 ),
202
+ const SizedBox (height: 8 ),
202
203
Row (
203
204
mainAxisAlignment: MainAxisAlignment .center,
204
205
children: [
205
206
ElevatedButton (
206
207
onPressed: () {
207
208
_sendSpanishInquisition ();
208
209
},
209
- child: Text ("Expect the unexpected." ),
210
+ child: const Text ("Expect the unexpected." ),
210
211
),
211
- SizedBox (width: 4 ),
212
+ const SizedBox (width: 4 ),
212
213
ElevatedButton (
213
214
onPressed: () {
214
215
_sendGrievous ();
215
216
},
216
- child: Text ("Star Wars" ),
217
+ child: const Text ("Star Wars" ),
217
218
),
218
219
],
219
220
),
220
221
],
221
222
),
222
- SizedBox (height: 24 ),
223
+ const SizedBox (height: 24 ),
223
224
Column (
224
225
children: [
225
226
// Control timer notification
226
227
Text ("Timer Notification" , style: _boldTextStyle),
227
- SizedBox (height: 4 ),
228
+ const SizedBox (height: 4 ),
228
229
Row (
229
230
mainAxisAlignment: MainAxisAlignment .center,
230
231
children: [
231
232
ElevatedButton (
232
233
onPressed: () {
233
234
_startTimerNotification ();
234
235
},
235
- child: Icon (Icons .play_arrow),
236
+ child: const Icon (Icons .play_arrow),
236
237
),
237
- SizedBox (width: 8 ),
238
+ const SizedBox (width: 8 ),
238
239
ElevatedButton (
239
240
onPressed: () {
240
241
_pauseTimerNotification ();
241
242
},
242
- child: Icon (Icons .pause),
243
+ child: const Icon (Icons .pause),
243
244
),
244
- SizedBox (width: 8 ),
245
+ const SizedBox (width: 8 ),
245
246
ElevatedButton (
246
247
onPressed: () {
247
248
_stopTimerNotification ();
248
249
},
249
- child: Icon (Icons .stop),
250
+ child: const Icon (Icons .stop),
250
251
)
251
252
],
252
253
),
253
254
],
254
255
),
255
- SizedBox (height: 8 ),
256
+ const SizedBox (height: 8 ),
256
257
Row (
257
258
mainAxisAlignment: MainAxisAlignment .center,
258
259
children: [
259
260
ElevatedButton (
260
261
onPressed: () {
261
262
_showTimerNotification ();
262
263
},
263
- child: Text ("Show Timer Notification" ),
264
+ child: const Text ("Show Timer Notification" ),
264
265
),
265
- SizedBox (width: 8 ),
266
+ const SizedBox (width: 8 ),
266
267
ElevatedButton (
267
268
onPressed: () {
268
269
_hideTimerNotification ();
269
270
},
270
- child: Text ("Hide Timer Notification" ),
271
+ child: const Text ("Hide Timer Notification" ),
271
272
),
272
273
],
273
274
),
274
- SizedBox (height: 24 ),
275
+ const SizedBox (height: 24 ),
275
276
ElevatedButton (
276
277
onPressed: () {
277
278
_clearAllNotifications ();
278
279
},
279
- child: Text ("Clear All" ),
280
+ child: const Text ("Clear All" ),
280
281
),
281
282
],
282
283
),
@@ -285,20 +286,21 @@ class _MyAppState extends State<MyApp> {
285
286
}
286
287
287
288
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 = {
292
293
"string" : "string" ,
293
294
"1" : 1 ,
294
295
"false" : false ,
295
296
"1.1" : 1.1 ,
296
297
'c' : 'c' ,
297
298
'[]' : [],
298
299
'{}' : {},
300
+ if (data != null ) ...data,
299
301
};
300
302
301
- return _jsNotificationsPlugin.showNotification (_title , body: _body , data: _data , tag: _id );
303
+ return _jsNotificationsPlugin.showNotification (title0 , body: body0 , data: data0 , tag: id0 );
302
304
}
303
305
304
306
Future <void > _sendBasicNotification (String title, {String ? tag}) {
@@ -316,8 +318,8 @@ class _MyAppState extends State<MyApp> {
316
318
tag: "inquisition" ,
317
319
icon: "https://pbs.twimg.com/media/CtCG_f4WcAAJY-1.jpg" ,
318
320
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" ),
321
323
],
322
324
requireInteraction: true ,
323
325
);
@@ -331,8 +333,8 @@ class _MyAppState extends State<MyApp> {
331
333
icon:
332
334
"https://www.liveabout.com/thmb/F5lfgFptU9DNTDCT-xNEtot0lQ0=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/EP2-IA-60435_R_8x10-56a83bea3df78cf7729d314a.jpg" ,
333
335
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" ),
336
338
],
337
339
requireInteraction: true ,
338
340
);
@@ -345,8 +347,8 @@ class _MyAppState extends State<MyApp> {
345
347
body: "You acknowledge he is a bold one. What do you do?" ,
346
348
icon: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQvS2A_Sb7z7dXcrPVscT0FeCdFO7IM88U2vg&s" ,
347
349
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" ),
350
352
],
351
353
requireInteraction: true ,
352
354
);
@@ -365,8 +367,8 @@ class _MyAppState extends State<MyApp> {
365
367
"Timer" ,
366
368
tag: _notificationTagStopwatch,
367
369
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" ),
370
372
],
371
373
requireInteraction: true ,
372
374
);
0 commit comments