【问题标题】:How to display an image in flutter without changing its scale or aspect ratio如何在不改变其比例或纵横比的情况下以颤动方式显示图像
【发布时间】:2021-03-31 12:35:31
【问题描述】:

我想在我的颤振应用程序中显示图像而不更改其属性。鉴于我有一些图像的宽度比高度长,反之亦然。我试过不使用高度和宽度属性,但它仍然会影响一些图像。

这是我的代码

                      child: Column(
                        children: <Widget>[
                          Stack(
                              alignment: Alignment.bottomCenter,
                              children: <Widget>[
                                Image.network(
                                  widget.post.imageUrls[0],
                                  height: MediaQuery.of(context).size.height*0.3,
                                  fit: BoxFit.cover,
                                ),
                                Container(
                                  width: screenWidth(context)*0.2,
                                  padding: EdgeInsets.all(5),
                                  decoration: BoxDecoration(
                                    borderRadius:BorderRadius.circular(10),
                                    color:Color.fromRGBO(0, 0, 0, 0.4),
                                  ),
                                  child: CountDownTimer(
                                    secondsRemaining: secs,
                                    whenTimeExpires: () {
                                      setState(() {
                                        hasTimerStopped = true;
                                      });
                                    },
                                    countDownTimerStyle: TextStyle(
                                      color: Colors.redAccent,
                                      fontSize: 14.0,
                                    ),
                                  ),
                                ),
                              ]
                          ),

            ...other elements in my column below ...

我可以使用什么小部件来安全地显示这些图像。

【问题讨论】:

    标签: flutter user-interface widget


    【解决方案1】:

    如果我的理解正确,您希望图像尽可能大并保持其比例?

    如果是这样,那么您可以使用 BoxFit.none 来保持纵横比和大小。你可以在这里阅读更多: https://api.flutter.dev/flutter/painting/BoxFit-class.html

    但有一件事困扰着我,为什么你将高度设置为屏幕的 30%,但仍然要求不调整图像大小(降低到屏幕高度的 30%)?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-22
      • 2018-04-29
      • 2013-05-12
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多