用多种填充颜色扑向半圈

发布于 2025-02-13 09:59:33 字数 672 浏览 0 评论 0原文

我想在颤音中创建它:

”在此处输入图像描述

我知道您可以创建一个半个圆圈,例如 this

但是我如何获得这些多种填充颜色?

我知道有lineargradient可以完成此操作。 (类似这样的东西

但是我需要起作用,但是我需要使用每个颜色截面作为一个分开的零件/小部件,因为我想在下一步中对它们进行动画。

我怎么能完成这个?

I would like to create this in Flutter:

Enter image description here

I know you can create a half circle like this.

But how I can get these multiple fill colors?

I know there is way to get this done with LinearGradient. (something like this)

But this might work, but I need to each color-section as a separated part/widget because I want to animate them in the next step.

How could I get this done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平定天下 2025-02-20 09:59:33

您可以使用自定义画家来执行此操作,但是我知道将每个颜色棒的动画动画都是具有挑战性的。我已经能够创建类似您需要的东西

“

我使用夹板窗口小部件切出底部的底部和正方形的底部右部分 - >半圆。

每个颜色栏都是一个容器,由于您想为每个栏进行动画操作,因此您可以轻松地用AnimatedContainer替换容器,然后从那里继续进行。您可能还需要使动画的窗口小部件陈述。

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Assuming constraints here. 
    // Play with width and height values 
    const double widgetWidth = 100;
    const double widgetHeight = 60;
    // To get a semicircle
     const double bottomRadius = widgetWidth / 2;
    //Since we have 5 colors . Each color bars height is 60/5 = 12
    const double colorBarHeight = widgetHeight / 5;

return ClipRRect(
    borderRadius: const BorderRadius.only(
        bottomLeft: Radius.circular(bottomRadius),
        bottomRight: Radius.circular(bottomRadius)),
    child: SizedBox(
        width: widgetWidth,
        height: widgetHeight,
        child: Column(
          children: [
          Container(
              width: widgetWidth,height: colorBarHeight,color: Colors.green),
          Container(
              width: widgetWidth,height: colorBarHeight,color: Colors.orange),
          Container(
              width: widgetWidth,height: colorBarHeight,color: Colors.yellow),
          Container(
              width: widgetWidth, height: colorBarHeight, color: Colors.red),
          Container(
              width: widgetWidth, height: colorBarHeight, color: Colors.blue),
        ])));

}
}

You can do this using Custom Painter but then I understand it would be challenging to animate each color bar. I have been able to create something like you need

demo

I used the ClipRRect widget to cut out the bottomLeft and bottomRight portions of a square -> SemiCircle.

Each Color bar is a Container and since you would like to animate each bar you can easily replace the Container with an AnimatedContainer and proceed from there. You might also need to make the widget stateful for animations.

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Assuming constraints here. 
    // Play with width and height values 
    const double widgetWidth = 100;
    const double widgetHeight = 60;
    // To get a semicircle
     const double bottomRadius = widgetWidth / 2;
    //Since we have 5 colors . Each color bars height is 60/5 = 12
    const double colorBarHeight = widgetHeight / 5;

return ClipRRect(
    borderRadius: const BorderRadius.only(
        bottomLeft: Radius.circular(bottomRadius),
        bottomRight: Radius.circular(bottomRadius)),
    child: SizedBox(
        width: widgetWidth,
        height: widgetHeight,
        child: Column(
          children: [
          Container(
              width: widgetWidth,height: colorBarHeight,color: Colors.green),
          Container(
              width: widgetWidth,height: colorBarHeight,color: Colors.orange),
          Container(
              width: widgetWidth,height: colorBarHeight,color: Colors.yellow),
          Container(
              width: widgetWidth, height: colorBarHeight, color: Colors.red),
          Container(
              width: widgetWidth, height: colorBarHeight, color: Colors.blue),
        ])));

}
}

风追烟花雨 2025-02-20 09:59:33

请尝试以下代码:

class SemiCircle extends StatelessWidget {
  const SemiCircle({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Center(
            child: ClipRRect(
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(300),
                bottomRight: Radius.circular(300),
              ),
              child: Container(
                alignment: Alignment.center,
                height: 100,
                width: 200,
                child: Column(
                  children: [
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                    Container(
                      height: 10,
                      color: Colors.yellow,
                    ),
                    Container(
                      height: 10,
                      color: Colors.green,
                    ),
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                    Container(
                      height: 10,
                      color: Colors.yellow,
                    ),
                    Container(
                      height: 10,
                      color: Colors.green,
                    ),
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                    Container(
                      height: 10,
                      color: Colors.yellow,
                    ),
                    Container(
                      height: 10,
                      color: Colors.green,
                    ),
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

您将获得如下:

Please try this below code:

class SemiCircle extends StatelessWidget {
  const SemiCircle({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Center(
            child: ClipRRect(
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(300),
                bottomRight: Radius.circular(300),
              ),
              child: Container(
                alignment: Alignment.center,
                height: 100,
                width: 200,
                child: Column(
                  children: [
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                    Container(
                      height: 10,
                      color: Colors.yellow,
                    ),
                    Container(
                      height: 10,
                      color: Colors.green,
                    ),
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                    Container(
                      height: 10,
                      color: Colors.yellow,
                    ),
                    Container(
                      height: 10,
                      color: Colors.green,
                    ),
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                    Container(
                      height: 10,
                      color: Colors.yellow,
                    ),
                    Container(
                      height: 10,
                      color: Colors.green,
                    ),
                    Container(
                      height: 10,
                      color: Colors.red,
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

You will get an output like below:

Enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文