@@ -275,6 +275,7 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
275
275
late Future <void > _pendingRefreshFuture;
276
276
bool ? _isIndicatorAtTop;
277
277
double ? _dragOffset;
278
+ late Color _effectiveValueColor = widget.color ?? Theme .of (context).colorScheme.primary;
278
279
279
280
static final Animatable <double > _threeQuarterTween = Tween <double >(begin: 0.0 , end: 0.75 );
280
281
static final Animatable <double > _kDragSizeFactorLimitTween = Tween <double >(begin: 0.0 , end: _kDragSizeFactorLimit);
@@ -293,31 +294,15 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
293
294
294
295
@override
295
296
void didChangeDependencies () {
296
- final ThemeData theme = Theme .of (context);
297
- _valueColor = _positionController.drive (
298
- ColorTween (
299
- begin: (widget.color ?? theme.colorScheme.primary).withOpacity (0.0 ),
300
- end: (widget.color ?? theme.colorScheme.primary).withOpacity (1.0 ),
301
- ).chain (CurveTween (
302
- curve: const Interval (0.0 , 1.0 / _kDragSizeFactorLimit),
303
- )),
304
- );
297
+ _setupColorTween ();
305
298
super .didChangeDependencies ();
306
299
}
307
300
308
301
@override
309
302
void didUpdateWidget (covariant RefreshIndicator oldWidget) {
310
303
super .didUpdateWidget (oldWidget);
311
304
if (oldWidget.color != widget.color) {
312
- final ThemeData theme = Theme .of (context);
313
- _valueColor = _positionController.drive (
314
- ColorTween (
315
- begin: (widget.color ?? theme.colorScheme.primary).withOpacity (0.0 ),
316
- end: (widget.color ?? theme.colorScheme.primary).withOpacity (1.0 ),
317
- ).chain (CurveTween (
318
- curve: const Interval (0.0 , 1.0 / _kDragSizeFactorLimit),
319
- )),
320
- );
305
+ _setupColorTween ();
321
306
}
322
307
}
323
308
@@ -328,6 +313,28 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
328
313
super .dispose ();
329
314
}
330
315
316
+ void _setupColorTween () {
317
+ // Reset the current value color.
318
+ _effectiveValueColor = widget.color ?? Theme .of (context).colorScheme.primary;
319
+ final Color color = _effectiveValueColor;
320
+ if (color.alpha == 0x00 ) {
321
+ // Set an always stopped animation instead of a driven tween.
322
+ _valueColor = AlwaysStoppedAnimation <Color >(color);
323
+ } else {
324
+ // Respect the alpha of the given color.
325
+ _valueColor = _positionController.drive (
326
+ ColorTween (
327
+ begin: color.withAlpha (0 ),
328
+ end: color.withAlpha (color.alpha),
329
+ ).chain (
330
+ CurveTween (
331
+ curve: const Interval (0.0 , 1.0 / _kDragSizeFactorLimit),
332
+ ),
333
+ ),
334
+ );
335
+ }
336
+ }
337
+
331
338
bool _shouldStart (ScrollNotification notification) {
332
339
// If the notification.dragDetails is null, this scroll is not triggered by
333
340
// user dragging. It may be a result of ScrollController.jumpTo or ballistic scroll.
@@ -448,7 +455,7 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
448
455
newValue = math.max (newValue, 1.0 / _kDragSizeFactorLimit);
449
456
}
450
457
_positionController.value = clampDouble (newValue, 0.0 , 1.0 ); // this triggers various rebuilds
451
- if (_mode == _RefreshIndicatorMode .drag && _valueColor.value! .alpha == 0xFF ) {
458
+ if (_mode == _RefreshIndicatorMode .drag && _valueColor.value! .alpha == _effectiveValueColor.alpha ) {
452
459
_mode = _RefreshIndicatorMode .armed;
453
460
}
454
461
}
0 commit comments