diff --git a/packages/flutter/lib/src/material/refresh_indicator.dart b/packages/flutter/lib/src/material/refresh_indicator.dart index 9755c3e3ab..ad52bb7138 100644 --- a/packages/flutter/lib/src/material/refresh_indicator.dart +++ b/packages/flutter/lib/src/material/refresh_indicator.dart @@ -238,6 +238,22 @@ class RefreshIndicatorState extends State with TickerProviderS super.didChangeDependencies(); } + @override + void didUpdateWidget(covariant RefreshIndicator oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.color != widget.color) { + final ThemeData theme = Theme.of(context); + _valueColor = _positionController.drive( + ColorTween( + begin: (widget.color ?? theme.accentColor).withOpacity(0.0), + end: (widget.color ?? theme.accentColor).withOpacity(1.0), + ).chain(CurveTween( + curve: const Interval(0.0, 1.0 / _kDragSizeFactorLimit) + )), + ); + } + } + @override void dispose() { _positionController.dispose(); diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index 781e10350d..010b0ea119 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -677,4 +677,52 @@ void main() { await tester.pump(const Duration(seconds: 1)); // finish the indicator settle animation expect(find.byType(RefreshProgressIndicator), findsNothing); }); + + testWidgets('RefreshIndicator.color can be updated at runtime', (WidgetTester tester) async { + refreshCalled = false; + Color refreshIndicatorColor = Colors.green; + const Color red = Colors.red; + late StateSetter setState; + + await tester.pumpWidget( + MaterialApp( + home: StatefulBuilder( + builder: (BuildContext context, StateSetter stateSetter) { + setState = stateSetter; + return RefreshIndicator( + triggerMode: RefreshIndicatorTriggerMode.anywhere, + onRefresh: holdRefresh, + color: refreshIndicatorColor, + child: ListView( + reverse: true, + physics: const AlwaysScrollableScrollPhysics(), + children: const [ + SizedBox( + height: 200.0, + child: Text('X'), + ), + SizedBox( + height: 800.0, + child: Text('Y'), + ), + ], + ), + ); + }, + ), + ), + ); + + await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0); + await tester.pump(); + expect(tester.widget(find.byType(RefreshProgressIndicator)).valueColor!.value, refreshIndicatorColor.withOpacity(1.0)); + + setState(() { + refreshIndicatorColor = red; + }); + + await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0); + await tester.pump(); + expect(tester.widget(find.byType(RefreshProgressIndicator)).valueColor!.value, red.withOpacity(1.0)); + }); }