我有一个这样的行,有两个孩子:
----------------------
| wide child1 | child2 |
----------------------
是否有任何方法可以使每个像元的大小相等,以使每个像元的宽度等于最宽像元的宽度?像这样:
--------------------------
| wide child1 | child2 |
--------------------------
因此整个行的宽度为biggestCellWidth * numOfChildren
。
我无法通过内置的小部件实现这种行为,并试图实现MultiChildLayoutDelegate
,但由于我无法测量孩子,所以它也无法正常工作。
更新:
// in build function
Container(
height: 48,
child: Material(
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(16),
color: Theme.of(context).colorScheme.primary,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// this widgets should be equal in width
_buildButton(
text: "Review",
onTap: _onReviewTap,
),
_buildButton(
text: "Buy",
onTap: _onBuyTap,
),
],
),
),
);
Widget _buildButton({
@required String text,
@required Function onTap,
@required EdgeInsets padding,
}) {
return InkWell(
onTap: onTap,
child: Center(
child: Text(
text,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
),
),
),
);
}
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.amber,
height: 100,
),
),
Expanded(
child: Container(
color: Colors.amber,
height: 100,
),
),