在Flutter中如何将一个小部分的小部件放在另一个小部件之外?

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

how to a place half of the widget outside of another widget in flutter?

问题

I want to place the half of the badge inside the container above the three dots.

我想将徽章的一半放在容器内,位于三个点的上方。

英文:

I have a Column which has a 2 items : 1- badge and 2- container . I want to place the half of the badge inside the container , the image will be more clear ,

在Flutter中如何将一个小部分的小部件放在另一个小部件之外?

and here is the parts of code :

Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
              badges.Badge(
                badgeContent:
                Icon(Icons.check, color: Colors.white, size: 10),
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text('Triggered')
                ),
              ),
          Container(
            width: double.infinity,
            decoration: containerRadius(Colors.grey[200], 12),
            margin: EdgeInsets.all(4),
            child: Text('Description')
          ),
        ],
      );

is there any idea how can I place half of the badge inside the container above the three dots ? thanks

答案1

得分: 2

你可以使用 Stack 小部件,确保在 Stack 上使用 clipBehavior: Clip.none,,并用定位小部件(如 Align、Positioned 小部件)包装子元素。

 Stack(
  clipBehavior: Clip.none,
  children: [
    Positioned(
      right: -10, // 负值表示在外部
      top: -10,
      child: badges.Badge(
        badgeContent:
            Icon(Icons.check, color: Colors.white, size: 10),
        child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text('已触发')),
      ),
    ),
    Positioned.fill(
      child: Container(
          margin: EdgeInsets.all(4),
          child: Text('描述')),
    ),
  ],
),

注意:我已将 "Triggered" 和 "Description" 翻译成中文。

英文:

You can use Stack widget, make sure use clipBehavior: Clip.none, on Stack and wrap children with positional widget like Align, Positioned widget.

 Stack(
  clipBehavior: Clip.none,
  children: [
    Positioned(
      right: -10, // negative means outside
      top: -10,
      child: badges.Badge(
        badgeContent:
            Icon(Icons.check, color: Colors.white, size: 10),
        child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text('Triggered')),
      ),
    ),
    Positioned.fill(
      child: Container(

          // decoration: containerRadius(Colors.grey[200], 12),
          margin: EdgeInsets.all(4),
          child: Text('Description')),
    ),
  ],
),

huangapple
  • 本文由 发表于 2023年4月13日 22:41:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76006778.html
匿名

发表评论

匿名网友

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

确定