linear_progress_indicator.dart 732 B

12345678910111213141516171819202122232425262728
  1. import 'dart:math';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. class LinearProgressIndicator extends CustomPainter {
  5. final List<Color> colors;
  6. final double progress;
  7. LinearProgressIndicator(this.colors, this.progress);
  8. @override
  9. void paint(Canvas canvas, Size size) {
  10. Rect rect = Rect.fromLTRB(0, 0, size.width * min(1.0, progress), size.height);
  11. Paint valuePaint = Paint()
  12. ..shader = LinearGradient(
  13. begin: Alignment.centerLeft,
  14. end: Alignment.centerRight,
  15. colors: colors,
  16. ).createShader(rect);
  17. canvas.drawRect(rect, valuePaint);
  18. }
  19. @override
  20. bool shouldRepaint(covariant CustomPainter oldDelegate) {
  21. return false;
  22. }
  23. }