我需要在使用GestureDetector
打开URL的图像旁边添加文本。我在下面附上一张图片,以供参考,以便于理解。
这是此类的代码:
class SocialMedia extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Social Media"),
),
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('images/affedbackground.png'),
fit: BoxFit.cover,
),
),
// child: Padding(
// padding: const EdgeInsets.fromLTRB(8.0, 110.0, 8.0, 20.0),
child: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(24.0),
child: GestureDetector(
onTap: _launchURLInstagram,
child: Image.asset(
'images/instagram.png',
// On click should redirect to an URL
width: 32.0,
height: 32.0,
fit: BoxFit.contain,
),
),
),
GestureDetector(
onTap: _launchURLFacebook,
child: Image.asset(
'images/facebook.png', // On click should redirect to an URL
width: 32.0,
height: 32.0,
fit: BoxFit.contain,
),
)
],
),
),
// ),
);
}
_launchURLInstagram() async {
const url =
'https://instagram.com/';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
_launchURLFacebook() async {
const url = 'https://www.facebook.com/';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
}
答案 0 :(得分:0)
设置Row
而不是Image
:
GestureDetector(
child: Row(
children[
Text('...'),
Image.asset(
'images/instagram.png'...
),
]
),
这是您要找的吗?