我有一张图片,点击后应重定向到网页并在浏览器中打开。
这是我用于图像的代码,我有两张图像,一幅用于背景,第二幅用于超链接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,
)
],
),
),
),
);
}
答案 0 :(得分:1)
使用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';
}
}