The Code is as follows:
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:walletconnect_dart/walletconnect_dart.dart';
import 'package:url_launcher/url_launcher_string.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
var connector = WalletConnect(
bridge: 'https://bridge.walletconnect.org',
clientMeta: const PeerMeta(
name: 'My App',
description: 'An app for converting pictures to NFT',
url: 'https://walletconnect.org',
icons: [
'https://files.gitbook.com/v0/b/gitbook-legacy-files/o/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
]));
var _session, _uri, _signature;
Future<void> loginUsingMetamask(BuildContext context) async {
if (!connector.connected) {
try {
var session = await connector.createSession(onDisplayUri: (uri) async {
_uri = uri;
await launchUrl(Uri.parse(uri), mode: LaunchMode.externalApplication);
});
print(session.accounts[0]);
print(session.chainId);
setState(() {
_session = session;
});
} catch (exp) {
print(exp);
}
}
}
@override
Widget build(BuildContext context) {
connector.on(
'connect',
(session) => setState(
() {
_session = _session;
},
));
connector.on(
'session_update',
(payload) => setState(() {
_session = payload;
print(_session.accounts[0]);
print(_session.chainId);
}));
connector.on(
'disconnect',
(payload) => setState(() {
_session = null;
}));
return Scaffold(
appBar: AppBar(title: Text("Login Page")),
body: Column(children: [
ElevatedButton(
onPressed: () async {
loginUsingMetamask(context);
},
child: Text("Connect to Metamask"))
]),
);
}
}
I encounter the aforementioned errors when debugging in 'CallStack'; but the apk compiled version of the app runs fine except since ig the connector is not properly initialized the user is unable to get a popup on MetaMask to authorize the connection like this Demo Image/Connection Auth
Context: I am trying to use WalletConnect protocol to integrate Metamask to my flutter dapp via deeplinking; this code works fine on all the tutorials I've watched but all of them ran on an IoS emulator; i wonder if there's something diff about android.
Any help would be appreciated; thnx!