问题描述
我试图在我的 Flutter 应用程序中显示图像而不更改其属性。鉴于我有一些图像的宽度比高度长,反之亦然。我试过不使用高度和宽度属性,但它仍然会影响一些图像。
这是我的代码
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.4),child: CountDownTimer(
secondsRemaining: secs,whenTimeExpires: () {
setState(() {
hasTimerStopped = true;
});
},countDownTimerStyle: TextStyle(
color: Colors.redAccent,fontSize: 14.0,]
),...other elements in my column below ...
我可以使用什么小部件来安全地显示这些图像。
解决方法
如果我理解正确,您希望图像尽可能大并保持其比例?
如果是这样,那么您可以使用 BoxFit.none 来保持纵横比和大小。你可以在这里阅读更多: https://api.flutter.dev/flutter/painting/BoxFit-class.html
但是有一件事困扰着我,为什么您将高度设置为屏幕的 30% 但仍然要求不调整图像大小(减少到屏幕的 30% 高度)?