简体   繁体   English

如何使用 Flutter 创建多色进度条

[英]How to create a multicolor Progress Bar with Flutter

How can i create a multicolor Progress Bar in Flutter.如何在 Flutter 中创建多色进度条。 I read about the LinearProgressIndicator but i am not sure it will suffice.我阅读了有关 LinearProgressIndicator 的信息,但我不确定它是否足够。

I want to do something like this.我想做这样的事情。

文本

Please guide me on what widget to use.请指导我使用什么小部件。 I do not want full code.我不想要完整的代码。

You'll have to assemble it part by part.您必须逐个组装它。 I see five parts in the progress bar you show:我在您显示的进度栏中看到五个部分:

  1. A grey rectangle with a shadow/depth effect, curved corners具有阴影/深度效果、弯曲角的灰色矩形
  2. Green rectangle with white text (read: Container with border)带有白色文本的绿色矩形(阅读:带边框的容器)
  3. Amber rectangle with white text带有白色文本的琥珀色矩形
  4. Red rectangle with white text带有白色文本的红色矩形
  5. All the rectangles are horizontally (read: Row)所有矩形都是水平的(阅读:行)

The numbers will be changing as your event(s) are progressing.随着您的活动进行,这些数字会发生变化。 Now, this can be achieved with setState().现在,这可以通过 setState() 来实现。 So, lets' not worry about that.所以,让我们不要担心。 :) :)

Okay, as far the You need to prepare a class which takes one parameter and that's the progressPercentage .好的,就目前而言,您需要准备一个 class ,它采用一个参数,即progressPercentage Based on the percentage, you decide how many blocks to show and with what text.根据百分比,您可以决定显示多少块以及使用什么文本。 This simple code snippet draws green rectangle with some text on it.这个简单的代码片段绘制了带有一些文本的绿色矩形。 And this codepen shows multi color bar which might be fairly easy to convert into the progressbar.这个codepen显示了多色条,它可能很容易转换成进度条。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM