【问题标题】:Flutter image does not fit in颤振图像不适合
【发布时间】:2020-02-09 20:31:44
【问题描述】:
Container(
  width:
  MediaQuery.of(context).size.width / 4.4,
  height:
  MediaQuery.of(context).size.height / 10,
  decoration: BoxDecoration(
    border: Border.all(
        color: Colors.black12,
        width: 1.5,
        style: BorderStyle.solid),
    borderRadius:
    BorderRadius.all(Radius.circular(20)),
  ),
  child: (TmpBytesImage == null)
      ? Icon(Icons.camera_alt,
      color: Colors.black26)
      : Image.memory(TmpBytesImage,
      fit: BoxFit.fill),
),

我希望用图像填充Container

但图像看起来像忽略BoxDecoration

如何让图像看起来像这样Container

【问题讨论】:

  • 如果它不起作用,请告诉我。

标签: flutter dart flutter-layout


【解决方案1】:


只需使用Card,给它shape,然后将你的Container 放入其中。简单例子:

Card(
  elevation: 12,
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.all(Radius.circular(20)),
  ),
  child: ClipRRect(
    borderRadius: BorderRadius.all(Radius.circular(20)),
    child: Container(
    padding: EdgeInsets.all(20),
      width: MediaQuery.of(context).size.width / 2,
      height: MediaQuery.of(context).size.height / 4,
      child: Image.asset(
        chocolateImage,
        fit: BoxFit.fill,
      ),
    ),
  ),
),

【讨论】:

    【解决方案2】:

    尝试在容器装饰中添加图像

    喜欢这个

    decoration: BoxDecoration(
                            image: DecorationImage(
                              image:
                                  AssetImage('assets/image.jpg'),
                              fit: BoxFit.cover,
                            ),
    

    【讨论】:

    • 恭喜,好答案!但是...通知文件路径,必须在其中插入答案中提到的代码。以及大约应该放置哪条线。
    猜你喜欢
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 2020-10-01
    • 2022-01-15
    • 1970-01-01
    • 2021-07-19
    相关资源
    最近更新 更多