这是带有边框的图像的代码,
Container(
child: Image.network(
"https://drive.google.com/uc?export=view&id=139Wu8bbLz5ubRECzdEmZof8crfGhx0oA", height: 140,fit: BoxFit.cover),
decoration: BoxDecoration(
border: Border.all(color: Colors.black12, width: 1),
),
),
如何将文本添加到类似于给定图像的输出中?
发布于 2021-08-30 23:20:15
您可以使用Stack
,下面是一个示例:
Stack(
children: [
Container(
child: Image.network(
"https://drive.google.com/ucexport=view&id=1GgUaQNmNaY2h2oRqgBECQZzJ4I6MnV8G",
height: 140,
fit: BoxFit.cover,
),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(7)),
border: Border.all(color: Colors.black12, width: 1),
),
),
Positioned(
child: Text(
'Vegetables',
style: TextStyle(
fontSize: 42,
shadows: <Shadow>[
Shadow(
offset: Offset(1.0, 5.0),
blurRadius: 2.0,
color: Color.fromARGB(255, 0, 0, 0),
),
],
),
),
top: 45,
left: 20,
)
],
)
发布于 2021-08-30 23:14:29
与其将映像作为Container
的子级,您可以使用image:ImageDecoration
并将Text
作为子级:
Container(
child: Text('Vegetables'),
decoration: BoxDecoration(
image: const DecorationImage(
image: NetworkImage(
'https://drive.google.com/ucexport=view&id=1GgUaQNmNaY2h2oRqgBECQZzJ4I6MnV8G'),
fit: BoxFit.cover,
),
border: Border.all(color: Colors.black12, width: 1),
),
),
发布于 2021-08-30 23:18:37
尝试下面的代码,希望它对你有帮助。
Container(
height: 100,
width: 200,
child: Text(
'data',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
decoration: BoxDecoration(
image: const DecorationImage(
image: NetworkImage(
'https://drive.google.com/uc?export=view&id=1GgUaQNmNaY2h2oRqgBECQZzJ4I6MnV8G'),
fit: BoxFit.cover,
),
border: Border.all(color: Colors.black12, width: 1),
),
),
你的结果屏幕
https://stackoverflow.com/questions/68994308
复制