@@ -11,8 +11,9 @@ import 'package:tree_planting_protocol/utils/services/switch_chain_utils.dart';
1111class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
1212 final String ? title;
1313 final List <Widget >? actions;
14+ final Widget ? leading;
1415
15- const UniversalNavbar ({super .key, this .title, this .actions});
16+ const UniversalNavbar ({super .key, this .title, this .actions, this .leading });
1617
1718 @override
1819 Size get preferredSize => const Size .fromHeight (120.0 );
@@ -43,6 +44,9 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
4344 padding: const EdgeInsets .symmetric (horizontal: 8.0 ),
4445 child: Row (
4546 children: [
47+ if (leading != null ) ...[
48+ leading! ,
49+ ],
4650 Expanded (
4751 flex: 2 ,
4852 child: Row (
@@ -59,7 +63,7 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
5963 ),
6064 ),
6165 child: Image .asset (
62- 'assets/tree-navbar-images/logo.png' , // Fixed path to match your folder structure
66+ 'assets/tree-navbar-images/logo.png' ,
6367 width: 28 ,
6468 height: 28 ,
6569 fit: BoxFit .contain,
@@ -186,7 +190,7 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
186190 width: plantWidth,
187191 height: plantWidth,
188192 child: Image .asset (
189- 'assets/tree-navbar-images/$imagePath ' , // Fixed: consistent path
193+ 'assets/tree-navbar-images/$imagePath ' ,
190194 width: 28 ,
191195 height: 28 ,
192196 fit: BoxFit .contain,
@@ -213,7 +217,7 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
213217 height: plantWidth,
214218 margin: EdgeInsets .zero,
215219 child: Image .asset (
216- 'assets/tree-navbar-images/$imagePath ' , // Fixed: consistent path
220+ 'assets/tree-navbar-images/$imagePath ' ,
217221 width: 35 ,
218222 height: 35 ,
219223 fit: BoxFit .contain,
@@ -362,13 +366,43 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
362366
363367 Widget _buildConnectButton (
364368 BuildContext context, WalletProvider walletProvider) {
369+ // Determine the state and corresponding visual properties
370+ Color backgroundColor;
371+ Color borderColor;
372+ Color textColor;
373+ IconData iconData;
374+ String buttonText;
375+
376+ if (walletProvider.isConnecting) {
377+ backgroundColor = Colors .orange.shade50;
378+ borderColor = Colors .orange;
379+ textColor = Colors .orange.shade700;
380+ iconData = Icons .sync ;
381+ buttonText = 'Retry' ;
382+ // Keep clickable for retry functionality
383+ } else if (walletProvider.isConnected) {
384+ // This case shouldn't normally happen as connected state shows the wallet menu
385+ backgroundColor = Colors .green.shade50;
386+ borderColor = Colors .green;
387+ textColor = Colors .green.shade700;
388+ iconData = Icons .account_balance_wallet;
389+ buttonText = 'Connected' ;
390+ } else {
391+ // Disconnected state
392+ backgroundColor = Colors .white;
393+ borderColor = Colors .green;
394+ textColor = Colors .green.shade700;
395+ iconData = Icons .account_balance_wallet;
396+ buttonText = 'Connect' ;
397+ }
398+
365399 return Container (
366400 constraints: const BoxConstraints (maxWidth: 80 ), // Limit max width
367401 decoration: BoxDecoration (
368- color: Colors .white ,
402+ color: backgroundColor ,
369403 borderRadius: BorderRadius .circular (16 ),
370404 border: Border .all (
371- color: Colors .green ,
405+ color: borderColor ,
372406 width: 1 ,
373407 ),
374408 boxShadow: [
@@ -384,12 +418,22 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
384418 child: InkWell (
385419 borderRadius: BorderRadius .circular (16 ),
386420 onTap: () async {
387- final uri = await walletProvider.connectWallet ();
388- if (uri != null && context.mounted) {
389- showDialog (
390- context: context,
391- builder: (context) => WalletConnectDialog (uri: uri),
392- );
421+ if (walletProvider.isConnecting) {
422+ final uri = await walletProvider.forceReconnect ();
423+ if (uri != null && context.mounted) {
424+ showDialog (
425+ context: context,
426+ builder: (context) => WalletConnectDialog (uri: uri),
427+ );
428+ }
429+ } else {
430+ final uri = await walletProvider.connectWallet ();
431+ if (uri != null && context.mounted) {
432+ showDialog (
433+ context: context,
434+ builder: (context) => WalletConnectDialog (uri: uri),
435+ );
436+ }
393437 }
394438 },
395439 child: Padding (
@@ -398,17 +442,26 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
398442 child: Row (
399443 mainAxisSize: MainAxisSize .min,
400444 children: [
401- Icon (
402- Icons .account_balance_wallet,
403- size: 16 ,
404- color: Colors .green[700 ],
405- ),
445+ walletProvider.isConnecting
446+ ? SizedBox (
447+ width: 16 ,
448+ height: 16 ,
449+ child: CircularProgressIndicator (
450+ strokeWidth: 2 ,
451+ valueColor: AlwaysStoppedAnimation <Color >(textColor),
452+ ),
453+ )
454+ : Icon (
455+ iconData,
456+ size: 16 ,
457+ color: textColor,
458+ ),
406459 const SizedBox (width: 4 ),
407460 Flexible (
408461 child: Text (
409- 'Connect' ,
462+ buttonText ,
410463 style: TextStyle (
411- color: Colors .green[ 700 ] ,
464+ color: textColor ,
412465 fontWeight: FontWeight .w600,
413466 fontSize: 12 ,
414467 ),
0 commit comments