在 Flutter 中将 Row 分成相等的两半

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

我在卡片中有一个行小部件,我想将行完美地划分为卡片宽度的一半,并在每一半中放置一些居中的文本。因此,必须固定行的一半间距,并且每个文本必须在其所在的一半位置居中。这是一个例子:

enter image description here

有什么想法吗?

flutter layout widget flutter-layout flutter-row
3个回答
19
投票

试试这个

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    Expanded(child: Center(child: TextButton(...))),
    VerticalDivider(width: 1.0),
    Expanded(child: Center(child: TextButton(...))),
  ],
),

5
投票

就我而言,我尝试过这样

 @override
  Widget build(BuildContext context) {
    final _screen =  MediaQuery.of(context).size;
    return Column(
      children: [
        Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                width: _screen.width * 0.45,
                child: ...
              ),
              VerticalDivider(width: 1.0),
              Container(
                width: _screen.width * 0.45,
                child: ...
              ),
          ]
        ),
      ],
    );
  }

0
投票

这对我有用:

IntrinsicHeight (
  child: Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: [
    Expanded(child: Center(child: TextButton(...))),
    VerticalDivider(thickness: 1.3, color: Colors.red),
    Expanded(child: Center(child: TextButton(...))),
  ],
)) 
© www.soinside.com 2019 - 2024. All rights reserved.