在Flutter中,列中的行不会为其子元素留出空间。

21 浏览
0 Comments

在Flutter中,列中的行不会为其子元素留出空间。

我有一个包含两个扩展子项的Column小部件,其flex分别为2和1。

第二个子项是另一个包含3个Row子项的Column,每个Row子项都有两个文本。

在每个Row子项中,mainAxisAlignment: MainAxisAlignment.spaceBetween应该将两个文本推到边缘,但它们保持居中,中间没有空间。

你能看出为什么它们之间没有空间吗?

这是小部件的代码:

class DisplayCell extends StatelessWidget {

final AutoSizeGroup autoSizeGroup;

final String imageUrl;

final String name;

final String price;

final String vendor;

final Function onTap;

const DisplayCell(

{Key key,

this.autoSizeGroup,

this.imageUrl,

this.name,

this.price,

this.vendor,

this.onTap})

: super(key: key);

@override

Widget build(BuildContext context) {

return Container(

color: Colors.transparent,

padding: EdgeInsets.all(5),

child: Container(

padding: EdgeInsets.all(10),

decoration: BoxDecoration(

color: Colors.black.withAlpha(120),

borderRadius: BorderRadius.circular(5),

border: Border.all(color: Colors.redAccent, width: 1),

),

child: Column(

// mainAxisAlignment: MainAxisAlignment.spaceBetween,

children: [

Expanded(

flex: 2,

child: Image(

image: NetworkImage(imageUrl),

),

),

Expanded(

flex: 1,

child: Column(

mainAxisAlignment: MainAxisAlignment.spaceEvenly,

children: [

Row(

mainAxisAlignment: MainAxisAlignment.spaceBetween,

mainAxisSize: MainAxisSize.max,

children: [

AutoSizeText(

AppLocalizations.instance.text('Name:'),

style: TextStyle(color: Colors.white, fontSize: 12),

minFontSize: 8,

maxLines: 1,

group: autoSizeGroup,

),

// SizedBox(

// width: 10,

// ),

AutoSizeText(

name,

style: TextStyle(color: Colors.white, fontSize: 12),

minFontSize: 8,

maxLines: 1,

group: autoSizeGroup,

),

],

),

Row(

mainAxisAlignment: MainAxisAlignment.spaceBetween,

mainAxisSize: MainAxisSize.max,

children: [

AutoSizeText(

AppLocalizations.instance.text('Price:'),

style: TextStyle(color: Colors.white, fontSize: 12),

minFontSize: 8,

maxLines: 1,

group: autoSizeGroup,

),

// SizedBox(

// width: 10,

// ),

AutoSizeText(

price,

style: TextStyle(color: Colors.white, fontSize: 12),

minFontSize: 8,

maxLines: 1,

group: autoSizeGroup,

),

],

),

Row(

mainAxisAlignment: MainAxisAlignment.spaceBetween,

mainAxisSize: MainAxisSize.max,

children: [

AutoSizeText(

AppLocalizations.instance.text('Vendor:'),

style: TextStyle(color: Colors.white, fontSize: 12),

minFontSize: 8,

maxLines: 1,

group: autoSizeGroup,

),

// SizedBox(

// width: 10,

// ),

AutoSizeText(

vendor,

style: TextStyle(color: Colors.white, fontSize: 12),

minFontSize: 8,

maxLines: 1,

group: autoSizeGroup,

),

],

),

],

),

),

],

),

),

);

}

}

0