【问题标题】:Image gets shrinked when put inside Stack widget Flutter放入 Stack 小部件 Flutter 时图像会缩小
【发布时间】:2021-07-02 12:22:44
【问题描述】:

我的预期用户界面是让图像占据全宽并在其顶部放置文本。所以我是一个堆栈小部件,但它会缩小并且不会占用完整的宽度。

        body: ListView(

        children: [
          Stack(
   
            children: [
              Container(
                child: Image(
                     height:120.0,
                     
                  image: AssetImage('images/business.jpg'),
                ),
              ),
              Text("Business",style: TextStyle(fontSize: 30.0),)
            ],
          )
        ])

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    首先,据我查看您的代码,我认为不需要ListView 小部件。删除它并实现您要查找的内容,请将以下属性添加到 Image 小部件

    fit: BoxFit.cover,
    height: double.infinity,
    width: double.infinity
    

    所以最终版本应该是这样的:

    Image(
         fit: BoxFit.cover,
         height: double.infinity,
         width: double.infinity
    
         image: AssetImage('images/business.jpg'),
         ),
    

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 2021-10-13
      • 2020-07-03
      • 1970-01-01
      • 2020-09-09
      • 2020-08-20
      • 2022-12-09
      • 1970-01-01
      • 2023-01-25
      相关资源
      最近更新 更多