@@ -2,17 +2,20 @@ import 'dart:async';
22import 'dart:io' ;
33
44import 'package:bot_toast/bot_toast.dart' ;
5- import 'package:flutter/cupertino.dart' hide MenuItem;
6- import 'package:flutter/material.dart' hide MenuItem;
5+ import 'package:flutter/cupertino.dart' ;
6+ import 'package:flutter/foundation.dart' ;
7+ import 'package:flutter/material.dart' ;
78import 'package:preference_list/preference_list.dart' ;
89import 'package:tray_manager/tray_manager.dart' ;
910
1011const _kIconTypeDefault = 'default' ;
1112const _kIconTypeOriginal = 'original' ;
1213
1314class HomePage extends StatefulWidget {
15+ const HomePage ({super .key});
16+
1417 @override
15- _HomePageState createState () => _HomePageState ();
18+ State < HomePage > createState () => _HomePageState ();
1619}
1720
1821class _HomePageState extends State <HomePage > with TrayListener {
@@ -33,7 +36,7 @@ class _HomePageState extends State<HomePage> with TrayListener {
3336 super .dispose ();
3437 }
3538
36- void _handleSetIcon (String iconType) async {
39+ Future < void > _handleSetIcon (String iconType) async {
3740 _iconType = iconType;
3841 String iconPath =
3942 Platform .isWindows ? 'images/tray_icon.ico' : 'images/tray_icon.png' ;
@@ -48,10 +51,12 @@ class _HomePageState extends State<HomePage> with TrayListener {
4851 }
4952
5053 void _startIconFlashing () {
51- _timer = Timer .periodic (Duration (seconds: 1 ), (timer) async {
52- _handleSetIcon (_iconType == _kIconTypeOriginal
53- ? _kIconTypeDefault
54- : _kIconTypeOriginal);
54+ _timer = Timer .periodic (const Duration (seconds: 1 ), (timer) async {
55+ _handleSetIcon (
56+ _iconType == _kIconTypeOriginal
57+ ? _kIconTypeDefault
58+ : _kIconTypeOriginal,
59+ );
5560 });
5661 setState (() {});
5762 }
@@ -69,48 +74,51 @@ class _HomePageState extends State<HomePage> with TrayListener {
6974 PreferenceListSection (
7075 children: [
7176 PreferenceListItem (
72- title: Text ('destroy' ),
77+ title: const Text ('destroy' ),
7378 onTap: () {
7479 trayManager.destroy ();
7580 },
7681 ),
7782 PreferenceListItem (
78- title: Text ('setIcon' ),
83+ title: const Text ('setIcon' ),
7984 accessoryView: Row (
8085 children: [
81- Builder (builder: (_) {
82- bool isFlashing = (_timer != null && _timer! .isActive);
83- return CupertinoButton (
84- child:
85- isFlashing ? Text ('stop flash' ) : Text ('start flash' ),
86- onPressed:
87- isFlashing ? _stopIconFlashing : _startIconFlashing,
88- );
89- }),
86+ Builder (
87+ builder: (_) {
88+ bool isFlashing = (_timer != null && _timer! .isActive);
89+ return CupertinoButton (
90+ onPressed:
91+ isFlashing ? _stopIconFlashing : _startIconFlashing,
92+ child: isFlashing
93+ ? const Text ('stop flash' )
94+ : const Text ('start flash' ),
95+ );
96+ },
97+ ),
9098 CupertinoButton (
91- child: Text ('Default' ),
99+ child: const Text ('Default' ),
92100 onPressed: () => _handleSetIcon (_kIconTypeDefault),
93101 ),
94102 CupertinoButton (
95- child: Text ('Original' ),
103+ child: const Text ('Original' ),
96104 onPressed: () => _handleSetIcon (_kIconTypeOriginal),
97105 ),
98106 ],
99107 ),
100108 onTap: () => _handleSetIcon (_kIconTypeDefault),
101109 ),
102110 PreferenceListItem (
103- title: Text ('setIconPosition' ),
111+ title: const Text ('setIconPosition' ),
104112 accessoryView: Row (
105113 children: [
106114 CupertinoButton (
107- child: Text ('left' ),
115+ child: const Text ('left' ),
108116 onPressed: () {
109117 trayManager.setIconPosition (TrayIconPositon .left);
110118 },
111119 ),
112120 CupertinoButton (
113- child: Text ('right' ),
121+ child: const Text ('right' ),
114122 onPressed: () {
115123 trayManager.setIconPosition (TrayIconPositon .right);
116124 },
@@ -120,19 +128,19 @@ class _HomePageState extends State<HomePage> with TrayListener {
120128 onTap: () => _handleSetIcon (_kIconTypeDefault),
121129 ),
122130 PreferenceListItem (
123- title: Text ('setToolTip' ),
131+ title: const Text ('setToolTip' ),
124132 onTap: () async {
125133 await trayManager.setToolTip ('tray_manager' );
126134 },
127135 ),
128136 PreferenceListItem (
129- title: Text ('setTitle' ),
137+ title: const Text ('setTitle' ),
130138 onTap: () async {
131139 await trayManager.setTitle ('tray_manager' );
132140 },
133141 ),
134142 PreferenceListItem (
135- title: Text ('setContextMenu' ),
143+ title: const Text ('setContextMenu' ),
136144 onTap: () async {
137145 _menu ?? = Menu (
138146 items: [
@@ -161,15 +169,19 @@ class _HomePageState extends State<HomePage> with TrayListener {
161169 label: 'Item 1' ,
162170 checked: true ,
163171 onClick: (menuItem) {
164- print ('click item 1' );
172+ if (kDebugMode) {
173+ print ('click item 1' );
174+ }
165175 menuItem.checked = ! (menuItem.checked == true );
166176 },
167177 ),
168178 MenuItem .checkbox (
169179 label: 'Item 2' ,
170180 checked: false ,
171181 onClick: (menuItem) {
172- print ('click item 2' );
182+ if (kDebugMode) {
183+ print ('click item 2' );
184+ }
173185 menuItem.checked = ! (menuItem.checked == true );
174186 },
175187 ),
@@ -185,15 +197,19 @@ class _HomePageState extends State<HomePage> with TrayListener {
185197 label: 'Item 1' ,
186198 checked: true ,
187199 onClick: (menuItem) {
188- print ('click item 1' );
200+ if (kDebugMode) {
201+ print ('click item 1' );
202+ }
189203 menuItem.checked = ! (menuItem.checked == true );
190204 },
191205 ),
192206 MenuItem .checkbox (
193207 label: 'Item 2' ,
194208 checked: false ,
195209 onClick: (menuItem) {
196- print ('click item 2' );
210+ if (kDebugMode) {
211+ print ('click item 2' );
212+ }
197213 menuItem.checked = ! (menuItem.checked == true );
198214 },
199215 ),
@@ -232,13 +248,13 @@ class _HomePageState extends State<HomePage> with TrayListener {
232248 },
233249 ),
234250 PreferenceListItem (
235- title: Text ('popUpContextMenu' ),
251+ title: const Text ('popUpContextMenu' ),
236252 onTap: () async {
237253 await trayManager.popUpContextMenu ();
238254 },
239255 ),
240256 PreferenceListItem (
241- title: Text ('getBounds' ),
257+ title: const Text ('getBounds' ),
242258 onTap: () async {
243259 Rect ? bounds = await trayManager.getBounds ();
244260 if (bounds != null ) {
@@ -268,29 +284,39 @@ class _HomePageState extends State<HomePage> with TrayListener {
268284
269285 @override
270286 void onTrayIconMouseDown () {
271- print ('onTrayIconMouseDown' );
287+ if (kDebugMode) {
288+ print ('onTrayIconMouseDown' );
289+ }
272290 trayManager.popUpContextMenu ();
273291 }
274292
275293 @override
276294 void onTrayIconMouseUp () {
277- print ('onTrayIconMouseUp' );
295+ if (kDebugMode) {
296+ print ('onTrayIconMouseUp' );
297+ }
278298 }
279299
280300 @override
281301 void onTrayIconRightMouseDown () {
282- print ('onTrayIconRightMouseDown' );
302+ if (kDebugMode) {
303+ print ('onTrayIconRightMouseDown' );
304+ }
283305 // trayManager.popUpContextMenu();
284306 }
285307
286308 @override
287309 void onTrayIconRightMouseUp () {
288- print ('onTrayIconRightMouseUp' );
310+ if (kDebugMode) {
311+ print ('onTrayIconRightMouseUp' );
312+ }
289313 }
290314
291315 @override
292316 void onTrayMenuItemClick (MenuItem menuItem) {
293- print (menuItem.toJson ());
317+ if (kDebugMode) {
318+ print (menuItem.toJson ());
319+ }
294320 BotToast .showText (
295321 text: '${menuItem .toJson ()}' ,
296322 );
0 commit comments