【问题标题】:How can i make a container with this kind of decoration using Flutter如何使用 Flutter 制作具有这种装饰的容器
【发布时间】:2020-11-04 11:18:03
【问题描述】:

Please see image。我不太关心容器的孩子。只是装饰。我正在尝试实现黄色背景和右上角的复选图标。到目前为止,我只能制作容器并为其赋予边框颜色。

这是我目前为Container 编写的代码:

Container(
  height: 50,
  width: 90,
  decoration: BoxDecoration(
    border: Border.all(color:Colors.yelloAccent[100]),
    borderRadius: BorderRadius.all(Radius.circular(5),
    ),
    color: color,
  ),
  child: Center(child: Text(text, style: TextStyle(fontSize: 12, color: textColor, fontWeight: FontWeight.w900))),
);

【问题讨论】:

    标签: flutter colors containers border badge


    【解决方案1】:

    您可以在 Stack 小部件的帮助下轻松创建它。

    可以通过旋转Container 小部件并调整其位置来创建右上角的三角形。这可以通过Positioned & Transform 小部件来实现。

    最后,复选标记图标可以放在三角形顶部的另一个Positioned 小部件中。

    这里,这个 sn-p 可能会对你有所帮助:

    return Stack(
          children: [
            // The actual container with border
            Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(4),
                border: Border.all(color: Colors.amber, width: 2),
              ),
              padding: const EdgeInsets.symmetric(horizontal:36, vertical: 24),
              child: Text(
                'Payment',
                style: const TextStyle(
                  color: Colors.black87,
                ),
              ),
            ),
            
            // The top right triangular shape
            Positioned(
              top: -20,
              right: -80,
              child: Transform.rotate(
                angle: pi / 4,
                child: Container(
                color: Colors.amber,
                height: 50,
                width: 150,
              ),),
            ),
            
            // The Icon
            Positioned(
              top: -4,
              right: -8,
              child: Icon(Icons.done, color: Colors.white),
            ),
          ],
        );
    

    【讨论】:

    • 这完全帮助了我。感谢您的帮助。
    • 欢迎,伙计。您可以随时投票或接受答案,以便其他人可以看到您认为此答案有帮助。
    猜你喜欢
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 2016-03-12
    • 2015-08-13
    • 2014-04-14
    • 2022-01-20
    相关资源
    最近更新 更多