gpt4 book ai didi

flutter - 如何使用条形码结果在Flutter中打开WebView

转载 作者:行者123 更新时间:2023-12-03 03:15:17 26 4
gpt4 key购买 nike

我正在使用BarcodeScanner软件包。扫描QR码后得到结果。我的问题是如何使用该结果然后打开网站。这是我的代码:

Future scan() async{
Completer<WebViewController> _controller = Completer<WebViewController>();
try {
String barcode = await BarcodeScanner.scan();
setState(() {
this.barcode = barcode;
print(this.barcode);
WebView(
initialUrl: this.barcode,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
),
});
} on PlatformException catch (e) {
if (e.code == BarcodeScanner.CameraAccessDenied) {
setState(() {
this.barcode = 'The user did not grant the camera permission!';
});
} else {
setState(() => this.barcode = 'Unknown error: $e');
}
} on FormatException{
setState(() => this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
} catch (e) {
setState(() => this.barcode = 'Unknown error: $e');
}
}
}

最佳答案

如果您在此处使用Webview,则从扫描仪收到QR码后,您需要导航到新屏幕。像这样

  Navigator.push(
context,
MaterialPageRoute(builder: (context) => WebView(initUrl: data[index].homeLink))
);

否则,您可以使用url_launcher插件
https://pub.dev/packages/url_launcher

关于flutter - 如何使用条形码结果在Flutter中打开WebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60466420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com