build method

Widget build(
  1. BuildContext context
)
override

Override this method to build widgets that depend on the state of the listenable (e.g., the current value of the animation).

Implementation

Widget build(BuildContext context) {
  final animation = listenable as Animation<double>;
  Color progressColor = widget.progressColor;

  if (widget.changeColorValue != null) {
    final _colorTween = ColorTween(
      begin: widget.progressColor,
      end: widget.changeProgressColor,
    );

    progressColor = _colorTween.transform(transformValue(
      animation.value,
      widget.changeColorValue,
      widget.maxValue,
      5,
    ))!;
  }

  List<Widget> progressWidgets = [];
  Widget progressWidget = Container(
    decoration: BoxDecoration(
      color: widget.progressGradient != null ? null : progressColor,
      gradient: widget.progressGradient,
      borderRadius: widget._borderRadius,
      border: widget.border,
    ),
  );
  progressWidgets.add(progressWidget);

  if (widget.displayText != null) {
    Widget textProgress = Container(
      alignment: widget.direction == Axis.horizontal
          ? FractionalOffset(0.95, 0.5)
          : (widget.verticalDirection == VerticalDirection.up
              ? FractionalOffset(0.5, 0.05)
              : FractionalOffset(0.5, 0.95)),
      child: Text(
        widget.formatValue.call(
                animation.value * widget.maxValue, widget.formatValueFixed) +
            widget.displayText!,
        softWrap: false,
        style: widget.displayTextStyle,
      ),
    );
    progressWidgets.add(textProgress);
  }

  return Directionality(
    textDirection: TextDirection.ltr,
    child: Container(
      width: widget.direction == Axis.vertical ? widget.size : null,
      height: widget.direction == Axis.horizontal ? widget.size : null,
      decoration: BoxDecoration(
        color: widget.backgroundColor,
        borderRadius: widget._borderRadius,
        border: widget.border,
      ),
      child: Flex(
        direction: widget.direction,
        verticalDirection: widget.verticalDirection,
        children: <Widget>[
          Expanded(
            flex: (animation.value * 100).toInt(),
            child: Stack(
              children: progressWidgets,
            ),
          ),
          Expanded(
            flex: 100 - (animation.value * 100).toInt(),
            child: Container(),
          )
        ],
      ),
    ),
  );
}