1- import 'package:flutter/material.dart' ;
21import 'dart:async' ;
32//ignore: avoid_web_libraries_in_flutter
43import 'dart:html' as html;
54
5+ import 'package:flutter/foundation.dart' ;
6+ import 'package:flutter/material.dart' ;
67import 'package:js_notifications/interop/interop.dart' ;
78import 'package:js_notifications/js_notifications_web.dart' ;
89import 'package:js_notifications/platform_interface/js_notifications_platform_interface.dart' ;
9- import 'package:js_notifications/utils/utils.dart' ;
1010import 'package:stop_watch_timer/stop_watch_timer.dart' ;
1111
1212void main () {
@@ -61,77 +61,94 @@ class _MyAppState extends State<MyApp> {
6161 }
6262 case "confused" :
6363 {
64- _sendBasicNotification ("Go watch Star Wars, now!" , tag: "star_wars_channel" );
64+ _sendBasicNotification ("Go watch Star Wars, now!" ,
65+ tag: "star_wars_channel" );
6566 break ;
6667 }
6768 case "kill_him" :
6869 {
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" );
7072 break ;
7173 }
7274 case "watch_star_wars" :
7375 {
74- _sendBasicNotification ("Sure, click here to watch it." , tag: "rick_roll" );
76+ _sendBasicNotification ("Sure, click here to watch it." ,
77+ tag: "rick_roll" );
7578 break ;
7679 }
7780
78- case _notificationActionStopwatchStart: {
79- _startTimerNotification ();
80- break ;
81- }
81+ case _notificationActionStopwatchStart:
82+ {
83+ _startTimerNotification ();
84+ break ;
85+ }
8286
83- case _notificationActionStopwatchPause: {
84- _pauseTimerNotification ();
85- _onSecondTimerTick ();
86- break ;
87- }
87+ case _notificationActionStopwatchPause:
88+ {
89+ _pauseTimerNotification ();
90+ _onSecondTimerTick ();
91+ break ;
92+ }
8893
89- case _notificationActionStopwatchStop: {
90- _stopTimerNotification ();
91- _onSecondTimerTick ();
92- break ;
93- }
94+ case _notificationActionStopwatchStop:
95+ {
96+ _stopTimerNotification ();
97+ _onSecondTimerTick ();
98+ break ;
99+ }
94100
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+ }
101108
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+ }
108116
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+ }
114124 }
115- }
116125 }
117126 });
118127 _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+ }
128141 }
129142 });
130143 }
131144
132145 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+ }
135152 _jsNotificationsPlugin.showNotification (
136153 "Timer" ,
137154 body: formattedCallTime,
@@ -142,16 +159,22 @@ class _MyAppState extends State<MyApp> {
142159 silent: _stopwatchSilent,
143160 actions: [
144161 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" ),
147166 ] 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" ),
150171 ],
151172 if (_stopwatchSilent)
152- const JSNotificationAction (action: _notificationActionStopwatchHeadsUp, title: "Heads Up" )
173+ const JSNotificationAction (
174+ action: _notificationActionStopwatchHeadsUp, title: "Heads Up" )
153175 else
154- const JSNotificationAction (action: _notificationActionStopwatchSilent, title: "Silence" ),
176+ const JSNotificationAction (
177+ action: _notificationActionStopwatchSilent, title: "Silence" ),
155178 ],
156179 );
157180 }
@@ -175,7 +198,8 @@ class _MyAppState extends State<MyApp> {
175198 children: [
176199 ElevatedButton (
177200 onPressed: () {
178- _sendBasicNotification ("Test Notification" , tag: "test" );
201+ _sendBasicNotification ("Test Notification" ,
202+ tag: "test" );
179203 },
180204 child: const Text ("Test Notification" ),
181205 ),
@@ -285,7 +309,8 @@ class _MyAppState extends State<MyApp> {
285309 );
286310 }
287311
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}) {
289314 final id0 = id ?? "data-notification" ;
290315 final title0 = title ?? "Data Notification" ;
291316 final body0 = body ?? "A notification with some data too" ;
@@ -297,10 +322,11 @@ class _MyAppState extends State<MyApp> {
297322 'c' : 'c' ,
298323 '[]' : [],
299324 '{}' : {},
300- if (data != null ) ...data,
325+ if (data != null ) ...data,
301326 };
302327
303- return _jsNotificationsPlugin.showNotification (title0, body: body0, data: data0, tag: id0);
328+ return _jsNotificationsPlugin.showNotification (title0,
329+ body: body0, data: data0, tag: id0);
304330 }
305331
306332 Future <void > _sendBasicNotification (String title, {String ? tag}) {
@@ -314,12 +340,14 @@ class _MyAppState extends State<MyApp> {
314340 Future <void > _sendSpanishInquisition () {
315341 return _jsNotificationsPlugin.showNotification (
316342 "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..." ,
318345 tag: "inquisition" ,
319346 icon: "https://pbs.twimg.com/media/CtCG_f4WcAAJY-1.jpg" ,
320347 actions: [
321348 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" ),
323351 ],
324352 requireInteraction: true ,
325353 );
@@ -333,7 +361,8 @@ class _MyAppState extends State<MyApp> {
333361 icon:
334362 "https://www.liveabout.com/thmb/F5lfgFptU9DNTDCT-xNEtot0lQ0=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/EP2-IA-60435_R_8x10-56a83bea3df78cf7729d314a.jpg" ,
335363 actions: [
336- const JSNotificationAction (action: "general_kenobi" , title: "General Kenobi" ),
364+ const JSNotificationAction (
365+ action: "general_kenobi" , title: "General Kenobi" ),
337366 const JSNotificationAction (action: "confused" , title: "I'm confused" ),
338367 ],
339368 requireInteraction: true ,
@@ -345,10 +374,12 @@ class _MyAppState extends State<MyApp> {
345374 "Grievous" ,
346375 tag: "grievous_2" ,
347376 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" ,
349379 actions: [
350380 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" ),
352383 ],
353384 requireInteraction: true ,
354385 );
@@ -375,7 +406,8 @@ class _MyAppState extends State<MyApp> {
375406 }
376407
377408 void _startTimerNotification () {
378- _stopWatchTimerListener ?? = stopWatchTimer.secondTime.listen ((_) => _onSecondTimerTick ());
409+ _stopWatchTimerListener ?? =
410+ stopWatchTimer.secondTime.listen ((_) => _onSecondTimerTick ());
379411 _stopwatchSilent = false ;
380412 stopWatchTimer.onStartTimer ();
381413 }
0 commit comments