I implemented this in my app. Here's the code. Hope this helps
I have used the walletconnect_dart package to open the wallet from where the user can connect their wallet to the app and url_launcher to open the wallet
Future<void> connectWallet() async {
final connector = WalletConnect(
bridge: 'https://bridge.walletconnect.org',
clientMeta: const PeerMeta(
name: 'any name',
description: 'any description',
url: 'any url',
icons: [
'logo url'
],
),
);
// Subscribe to events
connector.on('connect', (session) {
debugPrint("connect: " + session.toString());
address = sessionStatus?.accounts[0];
chainId = sessionStatus?.chainId;
debugPrint("Address: " + address!);
debugPrint("Chain Id: " + chainId.toString());
});
connector.on('session_request', (payload) {
debugPrint("session request: " + payload.toString());
});
connector.on('disconnect', (session) {
debugPrint("disconnect: " + session.toString());
});
// Create a new session
if (!connector.connected) {
sessionStatus = await connector.createSession(
chainId: 137, //pass the chain id of a network. 137 is Polygon
onDisplayUri: (uri) {
AppMehtods.openUrl(uri); //call the launchUrl(uri) method
},
);
}
}