我有此代码行:
children: <Widget> [
Image(image: AssetImage('assets/images/myimage.jpg')),
SizedBox(height: 195),
Text(
'texthere',
)]
我看到图像,但是按图像时我找不到添加链接的解决方案...有人可以帮我吗?
谢谢。
url_launcher
pubspec.yaml
2)包装您的Image()
或整个父对象,例如Column()
与GestureDetector()
一起识别点击。例如:
child: GestureDetector(
child: Column(children: <Widget>[
Image(
image: AssetImage('assets/images/myimage.jpg'),
),
SizedBox(
height: 195,
),
Text('texthere')
]),
onTap: () {
openUrl();
},
),
3)添加onTap
,并在此处调用新方法:
void openUrl() async {
String url = "https://stackoverflow.com/";
if (await canLaunch(url)) {
await launch(url);
}
}
请记住,此方法为async
,并且导入来自:
import 'package:url_launcher/url_launcher.dart';