将图片超链接到Flutter中的URL [英] Hyperlinking an image to an URL in Flutter
本文介绍了将图片超链接到Flutter中的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张图片,点击后应重定向到网页并在浏览器中打开.
I have an image which on click should redirect to a webpage and open in a browser.
这是我用于图像的代码,我有两张图像,一幅是背景图像,第二幅是我需要超链接URL的位置.
Here's the code which I'm using for the image, I have got two images, one is for the background and the second one is where I need to hyperlink the 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,
)
],
),
),
),
);
}
推荐答案
使用此插件 :
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中的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文