dart – Flutter – 列中的空间均匀无法正常工作
发布时间:2020-12-14 14:51:41 所属栏目:百科 来源:网络整理
导读:Screenshot of the problem 我试图通过在彼此之间有均匀的空格将元素放在红色框中. (就像给每个人增加重量1).为此,我将“mainAxisAlignment:MainAxisAlignment.spaceEvenly”放在父列中,但它不起作用. Container( margin: EdgeInsets.only(bottom: 8.0),chi
Screenshot of the problem
我试图通过在彼此之间有均匀的空格将元素放在红色框中. (就像给每个人增加重量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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |