@@ -275,6 +275,7 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
275275 late Future <void > _pendingRefreshFuture;
276276 bool ? _isIndicatorAtTop;
277277 double ? _dragOffset;
278+ late Color _effectiveValueColor = widget.color ?? Theme .of (context).colorScheme.primary;
278279
279280 static final Animatable <double > _threeQuarterTween = Tween <double >(begin: 0.0 , end: 0.75 );
280281 static final Animatable <double > _kDragSizeFactorLimitTween = Tween <double >(begin: 0.0 , end: _kDragSizeFactorLimit);
@@ -293,31 +294,15 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
293294
294295 @override
295296 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 ();
305298 super .didChangeDependencies ();
306299 }
307300
308301 @override
309302 void didUpdateWidget (covariant RefreshIndicator oldWidget) {
310303 super .didUpdateWidget (oldWidget);
311304 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 ();
321306 }
322307 }
323308
@@ -328,6 +313,28 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
328313 super .dispose ();
329314 }
330315
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+
331338 bool _shouldStart (ScrollNotification notification) {
332339 // If the notification.dragDetails is null, this scroll is not triggered by
333340 // user dragging. It may be a result of ScrollController.jumpTo or ballistic scroll.
@@ -448,7 +455,7 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
448455 newValue = math.max (newValue, 1.0 / _kDragSizeFactorLimit);
449456 }
450457 _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 ) {
452459 _mode = _RefreshIndicatorMode .armed;
453460 }
454461 }
0 commit comments