LinearPainter constructor
LinearPainter({
- required double lineWidth,
- required double progress,
- required bool isRTL,
- required ColorGradientModel progressModel,
- required ColorGradientModel backgroundModel,
- StrokeCap strokeCap = StrokeCap.butt,
- MaskFilter? maskFilter,
- required bool clipLinearGradient,
- String centerText = '',
- 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);
}
}