LinearPainter constructor

LinearPainter({
  1. required double lineWidth,
  2. required double progress,
  3. required bool isRTL,
  4. required ColorGradientModel progressModel,
  5. required ColorGradientModel backgroundModel,
  6. StrokeCap strokeCap = StrokeCap.butt,
  7. MaskFilter? maskFilter,
  8. required bool clipLinearGradient,
  9. String centerText = '',
  10. TextStyle centerTextStyle = defaultTextStyle,
})

Implementation

LinearPainter({
  required this.lineWidth,
  required this.progress,
  required this.isRTL,
  required this.progressModel,
  required this.backgroundModel,
  this.strokeCap = StrokeCap.butt,
  this.maskFilter,
  required this.clipLinearGradient,
  this.centerText = '',
  this.centerTextStyle = defaultTextStyle,
}) {
  _paintBackground.color = backgroundModel.color ?? Color(0xFFB8C7CB);
  _paintBackground.style = PaintingStyle.stroke;
  _paintBackground.strokeWidth = lineWidth;
  var tempProgressColor = (progressModel.color ?? Colors.red);
  _paintLine.color = progress.toString() == '0.0'
      ? tempProgressColor.withOpacity(0.0)
      : tempProgressColor;
  _paintLine.style = PaintingStyle.stroke;
  _paintLine.strokeWidth = lineWidth;

  _paintLine.strokeCap = strokeCap;
  if (strokeCap == StrokeCap.square) {
    //这里不存在方形的,转译处理为全部都是圆角收尾
    _paintLine.strokeCap = StrokeCap.round;
    _paintBackground.strokeCap = StrokeCap.round;
  }
  if (centerText.isNotEmpty) {
    _textPainter = TextPainter(
        text: TextSpan(
            text: centerText,
            style: centerTextStyle.copyWith(
                color: progressModel.color ?? defaultColor)),
        textDirection: TextDirection.ltr);
  }
}