gpt4 book ai didi

flutter - 在 Flutter 中将图像超链接到 URL

转载 作者:行者123 更新时间:2023-12-02 03:31:38 25 4
gpt4 key购买 nike

我有一张图片,点击后应该重定向到网页并在浏览器中打开。

这是我用于图像的代码,我有两张图像,一张用于背景,第二张用于我需要超链接 URL 的地方。

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("About the app"),
),
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('images/upgradedbg.png'), // Background Image
fit: BoxFit.cover,
),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(8.0, 110.0, 8.0, 20.0),
child: ListView(
children: <Widget>[
Image.asset(
'images/madeby.png', // On click should redirect to an URL
width: 400.0,
height: 180.0,
fit: BoxFit.cover,
)
],
),
),
),
);
}

最佳答案

使用this plugin :

  Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("About the app"),
),
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('images/upgradedbg.png'), // Background Image
fit: BoxFit.cover,
),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(8.0, 110.0, 8.0, 20.0),
child: ListView(
children: <Widget>[
GestureDetector(
onTap: _launchURL,
child: Image.asset(
'images/madeby.png', // On click should redirect to an URL
width: 400.0,
height: 180.0,
fit: BoxFit.cover,
),
)
],
),
),
),
);
}
_launchURL() async {
const url = 'https://flutter.io';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}

关于flutter - 在 Flutter 中将图像超链接到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51708753/

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