Screenshot of the problem
我试图通过在彼此之间有均匀的空格将元素放在红色框中. (就像给每个人增加重量1).为此,我将“mainAxisAlignment:MainAxisAlignment.spaceEvenly”放在父列中,但它不起作用.
我试图通过在彼此之间有均匀的空格将元素放在红色框中. (就像给每个人增加重量1).为此,我将“mainAxisAlignment:MainAxisAlignment.spaceEvenly”放在父列中,但它不起作用.
Container( margin: EdgeInsets.only(bottom: 8.0),child: Row( crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[ CachedNetworkImage( imageUrl: "https://image.tmdb.org/t/p/w500/${movieDetails .posterPath}",height: 120.0,fit: BoxFit.fill),Expanded( child: Container( margin: EdgeInsets.only(left: 8.0),child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly,//NOT WORKING! children: <Widget>[ generateRow( Strings.released,movieDetails.releaseDate),generateRow(Strings.runtime,movieDetails.runtime.toString()),generateRow(Strings.budget,movieDetails.budget.toString()) ],))) ],)),
这是电影图像和红框的代码.我创建了一个包含2个元素的Row.第一个是图像,第二个是红色框.
Row generateRow(String key,String value) { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,children: <Widget>[Text(key),Text(value)],); }
我的generateRow方法
我怎么解决这个问题?
解决方法
由于您已经给出了图像的高度为120.0,您可以对其他Container子项执行相同的操作.通过这个,我能够实现你想要的.
代码段:
Container( margin: EdgeInsets.only(bottom: 8.0),child: Row( crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[ CachedNetworkImage( imageUrl: "https://image.tmdb.org/t/p/w500/${movieDetails .posterPath}",Expanded( child: Container( height: 120.0 //added to fix margin: EdgeInsets.only(left: 8.0),child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly,//NOT WORKING! children: <Widget>[ generateRow( Strings.released,movieDetails.budget.toString()) ],))) ],
调试提示:
>我使用Flutter Inspector来发现问题. Refer
>请参阅下图.即使我们给了Expanded,它只占图像大小的一半.这里Expanded的大小由孩子的大小(几乎是图像大小的一半)确定.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。