progress_indicator.dart 22.7 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math' as math;

7
import 'package:flutter/foundation.dart';
8
import 'package:flutter/widgets.dart';
9

10
import 'material.dart';
11
import 'theme.dart';
12 13

const double _kLinearProgressIndicatorHeight = 6.0;
14
const double _kMinCircularProgressIndicatorSize = 36.0;
15
const int _kIndeterminateLinearDuration = 1800;
16

17
// TODO(hansmuller): implement the support for buffer indicator
Hixie's avatar
Hixie committed
18

19
/// A base class for material design progress indicators.
20 21 22 23 24 25 26
///
/// This widget cannot be instantiated directly. For a linear progress
/// indicator, see [LinearProgressIndicator]. For a circular progress indicator,
/// see [CircularProgressIndicator].
///
/// See also:
///
27
///  * <https://material.io/design/components/progress-indicators.html>
28
abstract class ProgressIndicator extends StatefulWidget {
29 30
  /// Creates a progress indicator.
  ///
31 32 33 34
  /// {@template flutter.material.progressIndicator.parameters}
  /// The [value] argument can either be null for an indeterminate
  /// progress indicator, or non-null for a determinate progress
  /// indicator.
35 36 37 38 39 40 41
  ///
  /// ## Accessibility
  ///
  /// The [semanticsLabel] can be used to identify the purpose of this progress
  /// bar for screen reading software. The [semanticsValue] property may be used
  /// for determinate progress indicators to indicate how much progress has been made.
  /// {@endtemplate}
42
  const ProgressIndicator({
43
    Key key,
44 45
    this.value,
    this.backgroundColor,
46
    this.valueColor,
47 48
    this.semanticsLabel,
    this.semanticsValue,
49 50
  }) : super(key: key);

51 52 53
  /// If non-null, the value of this progress indicator.
  ///
  /// A value of 0.0 means no progress and 1.0 means that progress is complete.
54 55
  ///
  /// If null, this progress indicator is indeterminate, which means the
56
  /// indicator displays a predetermined animation that does not indicate how
57 58
  /// much actual progress is being made.
  final double value;
59

60 61 62
  /// The progress indicator's background color.
  ///
  /// The current theme's [ThemeData.backgroundColor] by default.
63 64
  final Color backgroundColor;

65 66 67
  /// The progress indicator's color as an animated value.
  ///
  /// To specify a constant color use: `AlwaysStoppedAnimation<Color>(color)`.
68
  ///
69
  /// If null, the progress indicator is rendered with the current theme's
70
  /// [ThemeData.accentColor].
71 72
  final Animation<Color> valueColor;

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  /// {@template flutter.material.progressIndicator.semanticsLabel}
  /// The [Semantics.label] for this progress indicator.
  ///
  /// This value indicates the purpose of the progress bar, and will be
  /// read out by screen readers to indicate the purpose of this progress
  /// indicator.
  /// {@endtemplate}
  final String semanticsLabel;

  /// {@template flutter.material.progressIndicator.semanticsValue}
  /// The [Semantics.value] for this progress indicator.
  ///
  /// This will be used in conjunction with the [semanticsLabel] by
  /// screen reading software to identify the widget, and is primarily
  /// intended for use with determinate progress indicators to announce
  /// how far along they are.
  ///
  /// For determinate progress indicators, this will be defaulted to [value]
  /// expressed as a percentage, i.e. `0.1` will become '10%'.
  /// {@endtemplate}
  final String semanticsValue;

95
  Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor;
96
  Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor;
97

98
  @override
99 100
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
101
    properties.add(PercentProperty('value', value, showName: false, ifNull: '<indeterminate>'));
Hixie's avatar
Hixie committed
102
  }
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

  Widget _buildSemanticsWrapper({
    @required BuildContext context,
    @required Widget child,
  }) {
    String expandedSemanticsValue = semanticsValue;
    if (value != null) {
      expandedSemanticsValue ??= '${(value * 100).round()}%';
    }
    return Semantics(
      label: semanticsLabel,
      value: expandedSemanticsValue,
      child: child,
    );
  }
118 119
}

120
class _LinearProgressIndicatorPainter extends CustomPainter {
121 122 123 124 125 126 127 128 129 130 131 132 133 134
  const _LinearProgressIndicatorPainter({
    this.backgroundColor,
    this.valueColor,
    this.value,
    this.animationValue,
    @required this.textDirection,
  }) : assert(textDirection != null);

  final Color backgroundColor;
  final Color valueColor;
  final double value;
  final double animationValue;
  final TextDirection textDirection;

135 136
  // The indeterminate progress animation displays two lines whose leading (head)
  // and trailing (tail) endpoints are defined by the following four curves.
137
  static const Curve line1Head = Interval(
138 139
    0.0,
    750.0 / _kIndeterminateLinearDuration,
140
    curve: Cubic(0.2, 0.0, 0.8, 1.0),
141
  );
142
  static const Curve line1Tail = Interval(
143 144
    333.0 / _kIndeterminateLinearDuration,
    (333.0 + 750.0) / _kIndeterminateLinearDuration,
145
    curve: Cubic(0.4, 0.0, 1.0, 1.0),
146
  );
147
  static const Curve line2Head = Interval(
148 149
    1000.0 / _kIndeterminateLinearDuration,
    (1000.0 + 567.0) / _kIndeterminateLinearDuration,
150
    curve: Cubic(0.0, 0.0, 0.65, 1.0),
151
  );
152
  static const Curve line2Tail = Interval(
153 154
    1267.0 / _kIndeterminateLinearDuration,
    (1267.0 + 533.0) / _kIndeterminateLinearDuration,
155
    curve: Cubic(0.10, 0.0, 0.45, 1.0),
156 157
  );

158
  @override
159
  void paint(Canvas canvas, Size size) {
160
    final Paint paint = Paint()
161
      ..color = backgroundColor
162
      ..style = PaintingStyle.fill;
163
    canvas.drawRect(Offset.zero & size, paint);
164

165
    paint.color = valueColor;
166

167 168 169
    void drawBar(double x, double width) {
      if (width <= 0.0)
        return;
170 171 172 173 174 175 176 177 178 179

      double left;
      switch (textDirection) {
        case TextDirection.rtl:
          left = size.width - width - x;
          break;
        case TextDirection.ltr:
          left = x;
          break;
      }
180
      canvas.drawRect(Offset(left, 0.0) & Size(width, size.height), paint);
181
    }
182 183 184 185 186 187 188 189 190 191 192 193 194

    if (value != null) {
      drawBar(0.0, value.clamp(0.0, 1.0) * size.width);
    } else {
      final double x1 = size.width * line1Tail.transform(animationValue);
      final double width1 = size.width * line1Head.transform(animationValue) - x1;

      final double x2 = size.width * line2Tail.transform(animationValue);
      final double width2 = size.width * line2Head.transform(animationValue) - x2;

      drawBar(x1, width1);
      drawBar(x2, width2);
    }
195 196
  }

197
  @override
198 199 200 201
  bool shouldRepaint(_LinearProgressIndicatorPainter oldPainter) {
    return oldPainter.backgroundColor != backgroundColor
        || oldPainter.valueColor != valueColor
        || oldPainter.value != value
202 203
        || oldPainter.animationValue != animationValue
        || oldPainter.textDirection != textDirection;
204 205 206
  }
}

207
/// A material design linear progress indicator, also known as a progress bar.
208 209 210 211 212 213 214 215 216 217 218 219 220
///
/// A widget that shows progress along a line. There are two kinds of linear
/// progress indicators:
///
///  * _Determinate_. Determinate progress indicators have a specific value at
///    each point in time, and the value should increase monotonically from 0.0
///    to 1.0, at which time the indicator is complete. To create a determinate
///    progress indicator, use a non-null [value] between 0.0 and 1.0.
///  * _Indeterminate_. Indeterminate progress indicators do not have a specific
///    value at each point in time and instead indicate that progress is being
///    made without indicating how much progress remains. To create an
///    indeterminate progress indicator, use a null [value].
///
221 222 223
/// The indicator line is displayed with [valueColor], an animated value. To
/// specify a constant color value use: `AlwaysStoppedAnimation<Color>(color)`.
///
224 225
/// See also:
///
226 227 228
///  * [CircularProgressIndicator], which shows progress along a circular arc.
///  * [RefreshIndicator], which automatically displays a [CircularProgressIndicator]
///    when the underlying vertical scrollable is overscrolled.
229
///  * <https://material.io/design/components/progress-indicators.html#linear-progress-indicators>
230
class LinearProgressIndicator extends ProgressIndicator {
231 232
  /// Creates a linear progress indicator.
  ///
233
  /// {@macro flutter.material.progressIndicator.parameters}
234
  const LinearProgressIndicator({
235
    Key key,
236
    double value,
237 238
    Color backgroundColor,
    Animation<Color> valueColor,
239 240 241 242 243 244 245 246 247 248
    String semanticsLabel,
    String semanticsValue,
  }) : super(
         key: key,
         value: value,
         backgroundColor: backgroundColor,
         valueColor: valueColor,
         semanticsLabel: semanticsLabel,
         semanticsValue: semanticsValue,
       );
249

250
  @override
251
  _LinearProgressIndicatorState createState() => _LinearProgressIndicatorState();
252 253
}

254
class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with SingleTickerProviderStateMixin {
255 256
  AnimationController _controller;

257
  @override
258 259
  void initState() {
    super.initState();
260
    _controller = AnimationController(
261
      duration: const Duration(milliseconds: _kIndeterminateLinearDuration),
262
      vsync: this,
263 264 265 266 267 268 269 270 271 272 273 274
    );
    if (widget.value == null)
      _controller.repeat();
  }

  @override
  void didUpdateWidget(LinearProgressIndicator oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (widget.value == null && !_controller.isAnimating)
      _controller.repeat();
    else if (widget.value != null && _controller.isAnimating)
      _controller.stop();
275 276
  }

277
  @override
278
  void dispose() {
279
    _controller.dispose();
280 281 282
    super.dispose();
  }

283
  Widget _buildIndicator(BuildContext context, double animationValue, TextDirection textDirection) {
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    return widget._buildSemanticsWrapper(
      context: context,
      child: Container(
        constraints: const BoxConstraints(
          minWidth: double.infinity,
          minHeight: _kLinearProgressIndicatorHeight,
        ),
        child: CustomPaint(
          painter: _LinearProgressIndicatorPainter(
            backgroundColor: widget._getBackgroundColor(context),
            valueColor: widget._getValueColor(context),
            value: widget.value, // may be null
            animationValue: animationValue, // ignored if widget.value is not null
            textDirection: textDirection,
          ),
299 300
        ),
      ),
301 302 303
    );
  }

304
  @override
305
  Widget build(BuildContext context) {
306 307
    final TextDirection textDirection = Directionality.of(context);

308
    if (widget.value != null)
309
      return _buildIndicator(context, _controller.value, textDirection);
310

311
    return AnimatedBuilder(
312
      animation: _controller.view,
313
      builder: (BuildContext context, Widget child) {
314
        return _buildIndicator(context, _controller.value, textDirection);
315
      },
316 317 318 319
    );
  }
}

320
class _CircularProgressIndicatorPainter extends CustomPainter {
321
  _CircularProgressIndicatorPainter({
322
    this.backgroundColor,
323
    this.valueColor,
324 325 326 327 328
    this.value,
    this.headValue,
    this.tailValue,
    this.stepValue,
    this.rotationValue,
329
    this.strokeWidth,
330
  }) : arcStart = value != null
331 332
         ? _startAngle
         : _startAngle + tailValue * 3 / 2 * math.pi + rotationValue * math.pi * 1.7 - stepValue * 0.8 * math.pi,
333
       arcSweep = value != null
334 335
         ? value.clamp(0.0, 1.0) * _sweep
         : math.max(headValue * 3 / 2 * math.pi - tailValue * 3 / 2 * math.pi, _epsilon);
336

337
  final Color backgroundColor;
338 339
  final Color valueColor;
  final double value;
340 341 342 343
  final double headValue;
  final double tailValue;
  final int stepValue;
  final double rotationValue;
344 345 346
  final double strokeWidth;
  final double arcStart;
  final double arcSweep;
347

348 349 350 351 352 353
  static const double _twoPi = math.pi * 2.0;
  static const double _epsilon = .001;
  // Canvas.drawArc(r, 0, 2*PI) doesn't draw anything, so just get close.
  static const double _sweep = _twoPi - _epsilon;
  static const double _startAngle = -math.pi / 2.0;

354
  @override
355
  void paint(Canvas canvas, Size size) {
356
    final Paint paint = Paint()
357
      ..color = valueColor
358
      ..strokeWidth = strokeWidth
359
      ..style = PaintingStyle.stroke;
360 361 362 363 364 365 366
    if (backgroundColor != null) {
      final Paint backgroundPaint = Paint()
        ..color = backgroundColor
        ..strokeWidth = strokeWidth
        ..style = PaintingStyle.stroke;
      canvas.drawArc(Offset.zero & size, 0, _sweep, false, backgroundPaint);
    }
367

368
    if (value == null) // Indeterminate
369
      paint.strokeCap = StrokeCap.square;
370

371
    canvas.drawArc(Offset.zero & size, arcStart, arcSweep, false, paint);
372 373
  }

374
  @override
375
  bool shouldRepaint(_CircularProgressIndicatorPainter oldPainter) {
376 377
    return oldPainter.backgroundColor != backgroundColor
        || oldPainter.valueColor != valueColor
378
        || oldPainter.value != value
379 380 381
        || oldPainter.headValue != headValue
        || oldPainter.tailValue != tailValue
        || oldPainter.stepValue != stepValue
382 383
        || oldPainter.rotationValue != rotationValue
        || oldPainter.strokeWidth != strokeWidth;
384 385 386
  }
}

387 388
/// A material design circular progress indicator, which spins to indicate that
/// the application is busy.
389 390 391 392 393 394 395 396 397 398 399 400 401
///
/// A widget that shows progress along a circle. There are two kinds of circular
/// progress indicators:
///
///  * _Determinate_. Determinate progress indicators have a specific value at
///    each point in time, and the value should increase monotonically from 0.0
///    to 1.0, at which time the indicator is complete. To create a determinate
///    progress indicator, use a non-null [value] between 0.0 and 1.0.
///  * _Indeterminate_. Indeterminate progress indicators do not have a specific
///    value at each point in time and instead indicate that progress is being
///    made without indicating how much progress remains. To create an
///    indeterminate progress indicator, use a null [value].
///
402 403 404
/// The indicator arc is displayed with [valueColor], an animated value. To
/// specify a constant color use: `AlwaysStoppedAnimation<Color>(color)`.
///
405 406
/// See also:
///
407 408 409
///  * [LinearProgressIndicator], which displays progress along a line.
///  * [RefreshIndicator], which automatically displays a [CircularProgressIndicator]
///    when the underlying vertical scrollable is overscrolled.
410
///  * <https://material.io/design/components/progress-indicators.html#circular-progress-indicators>
411
class CircularProgressIndicator extends ProgressIndicator {
412 413
  /// Creates a circular progress indicator.
  ///
414
  /// {@macro flutter.material.progressIndicator.parameters}
415
  const CircularProgressIndicator({
416
    Key key,
417 418
    double value,
    Color backgroundColor,
419
    Animation<Color> valueColor,
420
    this.strokeWidth = 4.0,
421 422 423 424 425 426 427 428 429 430
    String semanticsLabel,
    String semanticsValue,
  }) : super(
         key: key,
         value: value,
         backgroundColor: backgroundColor,
         valueColor: valueColor,
         semanticsLabel: semanticsLabel,
         semanticsValue: semanticsValue,
       );
431

432 433 434
  /// The width of the line used to draw the circle.
  final double strokeWidth;

435
  @override
436
  _CircularProgressIndicatorState createState() => _CircularProgressIndicatorState();
437
}
438

439
// Tweens used by circular progress indicator
440
final Animatable<double> _kStrokeHeadTween = CurveTween(
441
  curve: const Interval(0.0, 0.5, curve: Curves.fastOutSlowIn),
442
).chain(CurveTween(
443
  curve: const SawTooth(5),
Hixie's avatar
Hixie committed
444 445
));

446
final Animatable<double> _kStrokeTailTween = CurveTween(
447
  curve: const Interval(0.5, 1.0, curve: Curves.fastOutSlowIn),
448
).chain(CurveTween(
449
  curve: const SawTooth(5),
Hixie's avatar
Hixie committed
450 451
));

452
final Animatable<int> _kStepTween = StepTween(begin: 0, end: 5);
Hixie's avatar
Hixie committed
453

454
final Animatable<double> _kRotationTween = CurveTween(curve: const SawTooth(5));
455

456
class _CircularProgressIndicatorState extends State<CircularProgressIndicator> with SingleTickerProviderStateMixin {
457
  AnimationController _controller;
458

459
  @override
460 461
  void initState() {
    super.initState();
462
    _controller = AnimationController(
463
      duration: const Duration(seconds: 5),
464
      vsync: this,
465 466 467 468 469 470 471 472 473 474 475 476
    );
    if (widget.value == null)
      _controller.repeat();
  }

  @override
  void didUpdateWidget(CircularProgressIndicator oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (widget.value == null && !_controller.isAnimating)
      _controller.repeat();
    else if (widget.value != null && _controller.isAnimating)
      _controller.stop();
477 478
  }

479
  @override
480
  void dispose() {
481
    _controller.dispose();
482 483 484
    super.dispose();
  }

485
  Widget _buildIndicator(BuildContext context, double headValue, double tailValue, int stepValue, double rotationValue) {
486 487 488 489 490 491 492 493 494
    return widget._buildSemanticsWrapper(
      context: context,
      child: Container(
        constraints: const BoxConstraints(
          minWidth: _kMinCircularProgressIndicatorSize,
          minHeight: _kMinCircularProgressIndicatorSize,
        ),
        child: CustomPaint(
          painter: _CircularProgressIndicatorPainter(
495
            backgroundColor: widget.backgroundColor,
496 497 498 499 500 501 502 503
            valueColor: widget._getValueColor(context),
            value: widget.value, // may be null
            headValue: headValue, // remaining arguments are ignored if widget.value is not null
            tailValue: tailValue,
            stepValue: stepValue,
            rotationValue: rotationValue,
            strokeWidth: widget.strokeWidth,
          ),
504 505
        ),
      ),
506 507 508
    );
  }

509
  Widget _buildAnimation() {
510
    return AnimatedBuilder(
511
      animation: _controller,
512
      builder: (BuildContext context, Widget child) {
513 514
        return _buildIndicator(
          context,
515 516 517
          _kStrokeHeadTween.evaluate(_controller),
          _kStrokeTailTween.evaluate(_controller),
          _kStepTween.evaluate(_controller),
518
          _kRotationTween.evaluate(_controller),
519
        );
520
      },
521 522
    );
  }
523 524 525

  @override
  Widget build(BuildContext context) {
526
    if (widget.value != null)
527 528 529
      return _buildIndicator(context, 0.0, 0.0, 0, 0.0);
    return _buildAnimation();
  }
530
}
531 532 533 534 535 536 537 538 539

class _RefreshProgressIndicatorPainter extends _CircularProgressIndicatorPainter {
  _RefreshProgressIndicatorPainter({
    Color valueColor,
    double value,
    double headValue,
    double tailValue,
    int stepValue,
    double rotationValue,
540
    double strokeWidth,
541
    this.arrowheadScale,
542 543 544 545 546 547 548
  }) : super(
    valueColor: valueColor,
    value: value,
    headValue: headValue,
    tailValue: tailValue,
    stepValue: stepValue,
    rotationValue: rotationValue,
549
    strokeWidth: strokeWidth,
550 551
  );

552 553
  final double arrowheadScale;

554 555
  void paintArrowhead(Canvas canvas, Size size) {
    // ux, uy: a unit vector whose direction parallels the base of the arrowhead.
Ian Hickson's avatar
Ian Hickson committed
556
    // (So ux, -uy points in the direction the arrowhead points.)
557 558 559 560 561 562
    final double arcEnd = arcStart + arcSweep;
    final double ux = math.cos(arcEnd);
    final double uy = math.sin(arcEnd);

    assert(size.width == size.height);
    final double radius = size.width / 2.0;
563 564 565 566 567
    final double arrowheadPointX = radius + ux * radius + -uy * strokeWidth * 2.0 * arrowheadScale;
    final double arrowheadPointY = radius + uy * radius +  ux * strokeWidth * 2.0 * arrowheadScale;
    final double arrowheadRadius = strokeWidth * 1.5 * arrowheadScale;
    final double innerRadius = radius - arrowheadRadius;
    final double outerRadius = radius + arrowheadRadius;
568

569
    final Path path = Path()
570 571
      ..moveTo(radius + ux * innerRadius, radius + uy * innerRadius)
      ..lineTo(radius + ux * outerRadius, radius + uy * outerRadius)
572
      ..lineTo(arrowheadPointX, arrowheadPointY)
573
      ..close();
574
    final Paint paint = Paint()
575 576 577 578 579 580 581 582 583
      ..color = valueColor
      ..strokeWidth = strokeWidth
      ..style = PaintingStyle.fill;
    canvas.drawPath(path, paint);
  }

  @override
  void paint(Canvas canvas, Size size) {
    super.paint(canvas, size);
584 585
    if (arrowheadScale > 0.0)
      paintArrowhead(canvas, size);
586 587 588
  }
}

589 590 591
/// An indicator for the progress of refreshing the contents of a widget.
///
/// Typically used for swipe-to-refresh interactions. See [RefreshIndicator] for
Adam Barth's avatar
Adam Barth committed
592
/// a complete implementation of swipe-to-refresh driven by a [Scrollable]
593 594
/// widget.
///
595 596 597
/// The indicator arc is displayed with [valueColor], an animated value. To
/// specify a constant color use: `AlwaysStoppedAnimation<Color>(color)`.
///
598 599
/// See also:
///
600 601
///  * [RefreshIndicator], which automatically displays a [CircularProgressIndicator]
///    when the underlying vertical scrollable is overscrolled.
602
class RefreshProgressIndicator extends CircularProgressIndicator {
603 604 605
  /// Creates a refresh progress indicator.
  ///
  /// Rather than creating a refresh progress indicator directly, consider using
Adam Barth's avatar
Adam Barth committed
606
  /// a [RefreshIndicator] together with a [Scrollable] widget.
607
  ///
608
  /// {@macro flutter.material.progressIndicator.parameters}
609
  const RefreshProgressIndicator({
610 611 612
    Key key,
    double value,
    Color backgroundColor,
613
    Animation<Color> valueColor,
614
    double strokeWidth = 2.0, // Different default than CircularProgressIndicator.
615 616
    String semanticsLabel,
    String semanticsValue,
617 618 619 620
  }) : super(
    key: key,
    value: value,
    backgroundColor: backgroundColor,
621 622
    valueColor: valueColor,
    strokeWidth: strokeWidth,
623 624
    semanticsLabel: semanticsLabel,
    semanticsValue: semanticsValue,
625
  );
626 627

  @override
628
  _RefreshProgressIndicatorState createState() => _RefreshProgressIndicatorState();
629 630 631
}

class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState {
632
  static const double _indicatorSize = 40.0;
633

634 635 636 637 638 639
  // Always show the indeterminate version of the circular progress indicator.
  // When value is non-null the sweep of the progress indicator arrow's arc
  // varies from 0 to about 270 degrees. When value is null the arrow animates
  // starting from wherever we left it.
  @override
  Widget build(BuildContext context) {
640 641
    if (widget.value != null)
      _controller.value = widget.value / 10.0;
642 643
    else if (!_controller.isAnimating)
      _controller.repeat();
644 645 646
    return _buildAnimation();
  }

647 648
  @override
  Widget _buildIndicator(BuildContext context, double headValue, double tailValue, int stepValue, double rotationValue) {
649
    final double arrowheadScale = widget.value == null ? 0.0 : (widget.value * 2.0).clamp(0.0, 1.0);
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
    return widget._buildSemanticsWrapper(
      context: context,
      child: Container(
        width: _indicatorSize,
        height: _indicatorSize,
        margin: const EdgeInsets.all(4.0), // accommodate the shadow
        child: Material(
          type: MaterialType.circle,
          color: widget.backgroundColor ?? Theme.of(context).canvasColor,
          elevation: 2.0,
          child: Padding(
            padding: const EdgeInsets.all(12.0),
            child: CustomPaint(
              painter: _RefreshProgressIndicatorPainter(
                valueColor: widget._getValueColor(context),
                value: null, // Draw the indeterminate progress indicator.
                headValue: headValue,
                tailValue: tailValue,
                stepValue: stepValue,
                rotationValue: rotationValue,
                strokeWidth: widget.strokeWidth,
                arrowheadScale: arrowheadScale,
              ),
673 674 675 676
            ),
          ),
        ),
      ),
677 678 679
    );
  }
}