David PHAM-VAN

Add LinearProgressIndicator

@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 4
5 - Fix Text.softWrap behavior 5 - Fix Text.softWrap behavior
6 - Add TableOfContent Widget 6 - Add TableOfContent Widget
  7 +- Add LinearProgressIndicator
7 8
8 ## 3.3.0 9 ## 3.3.0
9 10
@@ -62,7 +62,7 @@ class LimitedBox extends SingleChildWidget { @@ -62,7 +62,7 @@ class LimitedBox extends SingleChildWidget {
62 assert(child!.box != null); 62 assert(child!.box != null);
63 size = constraints.constrain(child!.box!.size); 63 size = constraints.constrain(child!.box!.size);
64 } else { 64 } else {
65 - size = _limitConstraints(constraints).constrain(PdfPoint.zero); 65 + size = _limitConstraints(constraints).smallest;
66 } 66 }
67 box = PdfRect.fromPoints(PdfPoint.zero, size); 67 box = PdfRect.fromPoints(PdfPoint.zero, size);
68 } 68 }
@@ -425,8 +425,8 @@ class ConstrainedBox extends SingleChildWidget { @@ -425,8 +425,8 @@ class ConstrainedBox extends SingleChildWidget {
425 assert(child!.box != null); 425 assert(child!.box != null);
426 box = child!.box; 426 box = child!.box;
427 } else { 427 } else {
428 - box = PdfRect.fromPoints(PdfPoint.zero,  
429 - this.constraints.enforce(constraints).constrain(PdfPoint.zero)); 428 + box = PdfRect.fromPoints(
  429 + PdfPoint.zero, this.constraints.enforce(constraints).smallest);
430 } 430 }
431 } 431 }
432 432
@@ -28,10 +28,14 @@ class CircularProgressIndicator extends Widget { @@ -28,10 +28,14 @@ class CircularProgressIndicator extends Widget {
28 this.strokeWidth = 4.0, 28 this.strokeWidth = 4.0,
29 this.backgroundColor}); 29 this.backgroundColor});
30 30
  31 + /// The value of this progress indicator.
  32 + /// A value of 0.0 means no progress and 1.0 means that progress is complete.
31 final double value; 33 final double value;
32 34
  35 + /// The progress indicator's color
33 final PdfColor? color; 36 final PdfColor? color;
34 37
  38 + /// The progress indicator's background color.
35 final PdfColor? backgroundColor; 39 final PdfColor? backgroundColor;
36 40
37 final double strokeWidth; 41 final double strokeWidth;
@@ -97,3 +101,64 @@ class CircularProgressIndicator extends Widget { @@ -97,3 +101,64 @@ class CircularProgressIndicator extends Widget {
97 } 101 }
98 } 102 }
99 } 103 }
  104 +
  105 +/// A material design linear progress indicator, also known as a progress bar.
  106 +class LinearProgressIndicator extends Widget {
  107 + /// Creates a linear progress indicator.
  108 + LinearProgressIndicator({
  109 + required this.value,
  110 + this.backgroundColor,
  111 + this.valueColor,
  112 + this.minHeight,
  113 + });
  114 +
  115 + /// The progress indicator's background color.
  116 + final PdfColor? backgroundColor;
  117 +
  118 + /// The minimum height of the line used to draw the indicator.
  119 + final double? minHeight;
  120 +
  121 + /// The value of this progress indicator.
  122 + /// A value of 0.0 means no progress and 1.0 means that progress is complete.
  123 + final double value;
  124 +
  125 + /// The progress indicator's color
  126 + final PdfColor? valueColor;
  127 +
  128 + @override
  129 + void layout(Context context, BoxConstraints constraints,
  130 + {bool parentUsesSize = false}) {
  131 + box = PdfRect.fromPoints(
  132 + PdfPoint.zero,
  133 + BoxConstraints(
  134 + minWidth: double.infinity,
  135 + minHeight: minHeight ?? 4.0,
  136 + ).enforce(constraints).smallest,
  137 + );
  138 + }
  139 +
  140 + @override
  141 + void paint(Context context) {
  142 + super.paint(context);
  143 +
  144 + final vc = value.clamp(0.0, 1.0);
  145 + final _valueColor = valueColor ?? PdfColors.blue;
  146 + final _backgroundColor = backgroundColor ?? _valueColor.shade(0.1);
  147 +
  148 + if (vc < 1.0) {
  149 + final epsilon = vc == 0 ? 0 : 0.01;
  150 + context.canvas
  151 + ..drawRect(box!.left + box!.width * vc - epsilon, box!.bottom,
  152 + box!.width * (1 - vc) + epsilon, box!.height)
  153 + ..setFillColor(_backgroundColor)
  154 + ..fillPath();
  155 + }
  156 +
  157 + if (vc > 0.0) {
  158 + context.canvas
  159 + ..drawRect(box!.left, box!.bottom, box!.width * vc, box!.height)
  160 + ..setFillColor(_valueColor)
  161 + ..fillPath();
  162 + }
  163 + }
  164 +}