为行中的所有子项设置相等的大小

问题描述 投票:0回答:2

我有一个这样的行,有两个孩子:

 ----------------------
| 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,
          ),
        ),
      ),
    );
  }
flutter flutter-layout flutter-widget
2个回答
0
投票
将您的child1和child2包裹在Expanded中,

Row( children: <Widget>[ Expanded( child: Container( color: Colors.amber, height: 100, ), ), Expanded( child: Container( color: Colors.amber, height: 100, ), ),


-1
投票
您可以将每个小部件包装在Flex中并使用相同的弹性编号
© www.soinside.com 2019 - 2024. All rights reserved.