12345678910111213141516171819202122232425262728 |
- import 'dart:math';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- class LinearProgressIndicator extends CustomPainter {
- final List<Color> colors;
- final double progress;
- LinearProgressIndicator(this.colors, this.progress);
- @override
- void paint(Canvas canvas, Size size) {
- Rect rect = Rect.fromLTRB(0, 0, size.width * min(1.0, progress), size.height);
- Paint valuePaint = Paint()
- ..shader = LinearGradient(
- begin: Alignment.centerLeft,
- end: Alignment.centerRight,
- colors: colors,
- ).createShader(rect);
- canvas.drawRect(rect, valuePaint);
- }
- @override
- bool shouldRepaint(covariant CustomPainter oldDelegate) {
- return false;
- }
- }
|