为图像小部件 Flutter 添加边框

问题描述 投票:0回答:1

我是 dart/flutter 新手,并尝试在该图像小部件周围添加一个小的黑色边框,但我不知道如何操作。

代码:

Align(
  alignment: const Alignment(0.0, -0.15),
  child: image.isNotEmpty
      ? Image.asset(
          image,
          width: 400,
          height: 200,
          fit: BoxFit.cover,
        )
      : SizedBox.shrink(),
),
flutter dart widget
1个回答
0
投票

您可以将

Container
DecorationImage
一起使用。

Container(
  width: 400,
  height: 200,
  decoration: BoxDecoration(
    borderRadius: BorderRadius.circular(8),
    border: Border.all(
      color: Colors.deepPurpleAccent,
      width: 2,
    ),
    image: DecorationImage(
      fit: BoxFit.cover,
      image: AssetImage(image),
    ),
  ),
),
© www.soinside.com 2019 - 2024. All rights reserved.