如何在Flutter中创建一个随机堆叠的容器?

huangapple go评论68阅读模式
英文:

How do I create a random stack of containers in flutter?

问题

看这个:

我正在尝试在Flutter中复制这个,但似乎很难。

注意“Linguistics”标签正好位于医疗保健和数据科学之间。

还有这个:

我尝试过简单的Row/Columns,但它们出现了溢出错误。

Stack/Positioned在容器开始重叠时起作用。

英文:

see this : -

<img src="https://i.stack.imgur.com/Lvt1C.png">

I am trying to replicate this in Flutter but seems impossible

Notice how the "Linguistics" pill perfectly fits between healthcare and data science

and this : -

<img src="https://i.stack.imgur.com/Bf6kD.png">

I tried simple Row/Columns but they had overflow errors

Stack/Positioned was working until the containers started overlapping each other

答案1

得分: 1

你可以使用PositionedStack并根据需要自定义。以下是输出。

Stack(
  children: [
    Positioned(
      left: 40,
      top: 42,
      child: Transform.rotate(
        angle: math.pi / 20,
        child: Chip(
          backgroundColor: Colors.grey,
          label: Text("IT & Development"),
        ),
      ),
    ),
    Positioned(
      top: 80,
      child: Transform.rotate(
        angle: -math.pi / 12,
        child: Chip(
          backgroundColor: Colors.teal,
          label: Text("Healthcare"),
        ),
      ),
    ),
    Positioned(
      left: 87,
      top: 112,
      child: Transform.rotate(
        angle: math.pi / 6,
        child: Chip(
          backgroundColor: Colors.amber,
          label: Text("IT & Development"),
        ),
      ),
    ),
    Positioned(
      left: 30,
      top: 130,
      child: Transform.rotate(
        angle: math.pi / 10,
        child: Chip(
          backgroundColor: Colors.pink,
          label: Text("IT & Development"),
        ),
      ),
    ),
  ],
)
英文:

You can use positioned with stack and customize for yourself. Output is below.
如何在Flutter中创建一个随机堆叠的容器?

Stack(
              children: [
                Positioned(
                  left: 40,
                  top: 42,
                  child: Transform.rotate(
                    angle: math.pi / 20,
                    child: Chip(
                      backgroundColor: Colors.grey,
                      label: Text(&quot;IT &amp; Development&quot;),
                    ),
                  ),
                ),
                Positioned(
                  top: 80,
                  child: Transform.rotate(
                    angle: -math.pi / 12,
                    child: Chip(
                      backgroundColor: Colors.teal,
                      label: Text(&quot;Healthcare&quot;),
                    ),
                  ),
                ),
                Positioned(
                  left: 87,
                  top: 112,
                  child: Transform.rotate(
                    angle: math.pi / 6,
                    child: Chip(
                      backgroundColor: Colors.amber,
                      label: Text(&quot;IT &amp; Development&quot;),
                    ),
                  ),
                ),
                Positioned(
                  left: 30,
                  top: 130,
                  child: Transform.rotate(
                    angle: math.pi / 10,
                    child: Chip(
                      backgroundColor: Colors.pink,
                      label: Text(&quot;IT &amp; Development&quot;),
                    ),
                  ),
                ),
              ],
            ),

huangapple
  • 本文由 发表于 2023年6月19日 15:29:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76504485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定