英文:
Flutter: Get custom properties from Window Object
问题
在文档中提到,您可以通过检查window.ethereum != undefined
(在JS中)来确定Metamask是否已安装。
显然,在Flutter的Window对象中没有这个属性。是否有一个列出所有未知属性或类似的变量?
谢谢!
英文:
I am working on a Web3 Flutter website (just to learn flutter).
I would like to programmatically know if there is an extension installed or not (Metamask in this case).
In the documentation they say that I can check if Metamask is installed by checking if window.ethereum != undefined
(in JS).
Obviously, I don't have this property in the Window object of flutter..
Is there a variable that list all unknown properties or something like that?
Thanks!
答案1
得分: 1
你可以使用这个插件 https://pub.dev/packages/flutter_web3
有一个属性可以用作
Ethereum.isSupported
等同于ethereum != null
如果 (ethereum != null) {
尝试 {
// 提示用户连接到提供者,即确认连接模态框
final accs = await ethereum!
.requestAccount(); // 获取节点中的所有帐户
accs; // [foo, bar]
} on EthereumUserRejected {
print('用户拒绝了模态框');
}
}
英文:
you can use this plugin https://pub.dev/packages/flutter_web3
there is a property that you can use as
/ `Ethereum.isSupported` is the same as `ethereum != null`
if (ethereum != null) {
try {
// Prompt user to connect to the provider, i.e. confirm the connection modal
final accs = await ethereum!
.requestAccount(); // Get all accounts in node disposal
accs; // [foo,bar]
} on EthereumUserRejected {
print('User rejected the modal');
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论