【问题标题】:How to set Image fit on every devices in flutter如何在颤动中设置图像适合每台设备
【发布时间】:2020-12-13 13:09:31
【问题描述】:

我是 Flutter 的初学者,我只是使用 carosel_slider 包制作了一个简单的图像轮播应用程序。我想要的是一张应该在所有设备上都能看到的图像。图像宽度应大于高度。模拟器显示正常,但在我的设备上不行。我已经阅读了this post,但我仍然不知道该怎么做。

 AspectRatio(
            aspectRatio: 16 / 9,
            child: Container(
              margin: EdgeInsets.all(6.0),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8.0),
                image: DecorationImage(
                  image: NetworkImage(
                      "https://miro.medium.com/max/1200/1*ZMOh7JwiTAVVHF8e7sijNg.png"),
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),

【问题讨论】:

    标签: flutter dart carousel


    【解决方案1】:

    感谢**

    MediaQuery.of (context).size

    **,你可以得到手机的尺寸。您想在中篇文章中描述的事件与页面大小成比例,而不是给它一个固定的高度。无论如何,这是最合乎逻辑的事情。但在图像的情况下,有时它可能不会吃。所以你可能需要使用额外的修复属性。

     Container(
         alignment: Alignment.center,
         height: MediaQuery.of(context).size.height * 0.5,
         width: MediaQuery.of(context).size.width * 0.6,
          margin: EdgeInsets.all(6.0),
          decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8.0),
          image: DecorationImage(
           image: NetworkImage(
              "https://miro.medium.com/max/1200/1*ZMOh7JwiTAVVHF8e7sijNg.png"),
           fit: BoxFit.cover,
         ),
       ),
    

    【讨论】:

      猜你喜欢
      • 2017-03-21
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多