【问题标题】:how to use media query for height in flutter(with const)如何在颤振中使用媒体查询高度(带常量)
【发布时间】:2021-11-09 07:33:14
【问题描述】:

在 Flutter 中处理图像高度的媒体查询时。 (使用 assets.images )从资产加载图像,媒体查询显示此错误。

这是我使用的代码

      body: Column(
        children: [
          const Image(
              height: MediaQuery.of(context).size.height *0.2,
              width: 250,
              image: AssetImage('assets/logo/logo.jpg')),
          Text(
            'Login',
            style: GoogleFonts.lato(
              textStyle: const TextStyle(color: Colors.blue, letterSpacing: .5),
            ),


----------


          ),
        ],
      ),

> But it will work if i wrap the image widget with container and specify height for container.

【问题讨论】:

  • 去掉图片小部件前面添加的 const 关键字

标签: flutter


【解决方案1】:

尝试去掉const关键字,Widget不是固定的希望对你有帮助。

请参阅文档here 了解媒体查询

【讨论】:

    【解决方案2】:

    您传递给Imageheight 不是常量,因为context 不是常量。要修复它,只需删除 const 关键字即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多