Skip to content

Commit 81672df

Browse files
committed
add: incorrect chain widget
1 parent f8542d8 commit 81672df

4 files changed

Lines changed: 85 additions & 30 deletions

File tree

lib/components/universal_navbar.dart

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,34 +101,34 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
101101
child: Row(
102102
mainAxisAlignment: MainAxisAlignment.end,
103103
children: [
104-
Container(
105-
width: 36,
106-
height: 36,
107-
decoration: BoxDecoration(
108-
color: Colors.white.withOpacity(0.2),
109-
borderRadius: BorderRadius.circular(8),
110-
border: Border.all(
111-
color: Colors.white.withOpacity(0.3),
112-
width: 1,
113-
),
114-
),
115-
child: IconButton(
116-
padding: EdgeInsets.zero,
117-
icon: Icon(
118-
themeProvider.isDarkMode
119-
? Icons.light_mode
120-
: Icons.dark_mode,
121-
color: Colors.white,
122-
size: 18,
123-
),
124-
onPressed: () {
125-
themeProvider.toggleTheme();
126-
},
127-
tooltip: themeProvider.isDarkMode
128-
? 'Switch to Light Mode'
129-
: 'Switch to Dark Mode',
130-
),
131-
),
104+
// Container(
105+
// width: 36,
106+
// height: 36,
107+
// decoration: BoxDecoration(
108+
// color: Colors.white.withOpacity(0.2),
109+
// borderRadius: BorderRadius.circular(8),
110+
// border: Border.all(
111+
// color: Colors.white.withOpacity(0.3),
112+
// width: 1,
113+
// ),
114+
// ),
115+
// child: IconButton(
116+
// padding: EdgeInsets.zero,
117+
// icon: Icon(
118+
// themeProvider.isDarkMode
119+
// ? Icons.light_mode
120+
// : Icons.dark_mode,
121+
// color: Colors.white,
122+
// size: 18,
123+
// ),
124+
// onPressed: () {
125+
// themeProvider.toggleTheme();
126+
// },
127+
// tooltip: themeProvider.isDarkMode
128+
// ? 'Switch to Light Mode'
129+
// : 'Switch to Dark Mode',
130+
// ),
131+
// ),
132132
const SizedBox(width: 6),
133133
if (actions != null) ...actions!,
134134
if (walletProvider.isConnected &&
@@ -238,7 +238,8 @@ class UniversalNavbar extends StatelessWidget implements PreferredSizeWidget {
238238

239239
Widget _buildWalletMenu(BuildContext context, WalletProvider walletProvider) {
240240
return Container(
241-
constraints: const BoxConstraints(maxWidth: 100), // Limit max width
241+
constraints: const BoxConstraints(maxWidth: 100, minHeight: 20),
242+
// Limit max width
242243
decoration: BoxDecoration(
243244
color: Colors.white.withOpacity(0.95),
244245
borderRadius: BorderRadius.circular(16),

lib/providers/wallet_provider.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class WalletProvider extends ChangeNotifier {
3636
String? get currentAddress => _currentAddress;
3737
String get statusMessage => _statusMessage;
3838
String? get currentChainId => _currentChainId;
39+
String? get correctChainId => _correctChainId;
3940

4041
bool get isConnected => _isConnected;
4142
bool get isConnecting => _isConnecting;
43+
bool get g => _isConnecting;
4244
bool get isValidCurrentChain =>
4345
_currentChainId?.toString() == _correctChainId;
4446

lib/widgets/basic_scaffold.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:provider/provider.dart';
44
import 'package:tree_planting_protocol/components/universal_navbar.dart';
55
import 'package:tree_planting_protocol/components/bottom_navigation_widget.dart';
66
import 'package:tree_planting_protocol/providers/wallet_provider.dart';
7+
import 'package:tree_planting_protocol/widgets/wrong_chain_widget.dart'
8+
show buildWrongChainWidget;
79

810
class BaseScaffold extends StatelessWidget {
911
final Widget body;
@@ -35,7 +37,7 @@ class BaseScaffold extends StatelessWidget {
3537
? SafeArea(
3638
child: body,
3739
)
38-
: Text("Wrong chain man"),
40+
: Container(child: buildWrongChainWidget(context)),
3941
floatingActionButton: floatingActionButton,
4042
bottomNavigationBar: showBottomNavigation
4143
? BottomNavigationWidget(currentRoute: currentRoute)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:tree_planting_protocol/providers/wallet_provider.dart';
3+
import 'package:provider/provider.dart';
4+
import 'package:tree_planting_protocol/utils/services/switch_chain_utils.dart';
5+
6+
Widget buildWrongChainWidget(BuildContext context) {
7+
final walletProvider = Provider.of<WalletProvider>(context, listen: false);
8+
return Center(
9+
child: Container(
10+
decoration: BoxDecoration(
11+
color: Colors.white,
12+
border: Border.all(
13+
color: Colors.black,
14+
width: 2,
15+
),
16+
),
17+
child: Column(
18+
mainAxisAlignment: MainAxisAlignment.center,
19+
children: [
20+
const Icon(
21+
Icons.account_balance_wallet,
22+
size: 64,
23+
color: Colors.grey,
24+
),
25+
const SizedBox(height: 16),
26+
Text(
27+
'Please switch to the chain supported by Tree Planting Protocol i.e. ${walletProvider.correctChainId}',
28+
textAlign: TextAlign.center,
29+
style: const TextStyle(
30+
fontSize: 16,
31+
color: Colors.black,
32+
),
33+
),
34+
const SizedBox(height: 16),
35+
ElevatedButton(
36+
onPressed: () {
37+
showChainSelector(context, walletProvider);
38+
},
39+
style: ButtonStyle(
40+
backgroundColor: WidgetStateProperty.all(
41+
const Color.fromARGB(255, 28, 211, 129),
42+
),
43+
),
44+
child: const Text('Switch Chain'),
45+
),
46+
],
47+
),
48+
),
49+
);
50+
}

0 commit comments

Comments
 (0)