11import 'package:flutter/material.dart' ;
22import 'dart:async' ;
3+ //ignore: avoid_web_libraries_in_flutter
34import 'dart:html' as html;
45
5- import 'package:flutter/services.dart' ;
66import 'package:js_notifications/interop/interop.dart' ;
77import 'package:js_notifications/js_notifications_web.dart' ;
88import 'package:js_notifications/platform_interface/js_notifications_platform_interface.dart' ;
9+ import 'package:js_notifications/utils/utils.dart' ;
910import 'package:stop_watch_timer/stop_watch_timer.dart' ;
1011
1112void 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 );
0 commit comments