颤振堆栈不会使子项重叠

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

我正在尝试放置一条水平线(当前为Divider,但可以更改为CustomPaint)作为Row的背景。但是,无论子顺序如何,该行始终位于Row的前面。我不知道怎么了。这是代码。

Stack(
  children: <Widget>[
    Positioned.fill(
      child: const Divider(color: Colors.black),
    ),
    Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        Ink(
          decoration: ShapeDecoration(
            color: Colors.grey[350],
            shape: CircleBorder(),
          ),
          child: Padding(
            padding: const EdgeInsets.all(4),
            child: Icon(Icons.arrow_forward, size: 32)
          ),
        ),
        Ink(
          decoration: ShapeDecoration(
            color: Colors.grey[350],
            shape: CircleBorder(),
          ),
          child: Padding(
            padding: const EdgeInsets.all(4),
            child: Icon(Icons.location_on, size: 32)
          ),
        ),
        Ink(
          decoration: ShapeDecoration(
            color: Colors.grey[350],
            shape: CircleBorder(),
          ),
          child: Padding(
            padding: const EdgeInsets.all(4),
            child: Icon(Icons.flag, size: 32)
          ),
        ),
      ],
    ),
  ],
),

这是结果图像。

flutter flutter-layout
1个回答
1
投票

使用Container代替Ink

Stack(
  children: <Widget>[
    Positioned.fill(
      child: const Divider(color: Colors.black),
    ),
    Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        Container(
          decoration: ShapeDecoration(
            color: Colors.grey[350],
            shape: CircleBorder(),
          ),
          child: Padding(
            padding: const EdgeInsets.all(4),
            child: Icon(Icons.arrow_forward, size: 32)
          ),
        ),
        Container(
          decoration: ShapeDecoration(
            color: Colors.grey[350],
            shape: CircleBorder(),
          ),
          child: Padding(
            padding: const EdgeInsets.all(4),
            child: Icon(Icons.location_on, size: 32)
          ),
        ),
        Container(
          decoration: ShapeDecoration(
            color: Colors.grey[350],
            shape: CircleBorder(),
          ),
          child: Padding(
            padding: const EdgeInsets.all(4),
            child: Icon(Icons.flag, size: 32)
          ),
        ),
      ],
    ),
  ],
);
© www.soinside.com 2019 - 2024. All rights reserved.