Unverified Commit 0b590507 authored by Pedro Massango's avatar Pedro Massango Committed by GitHub

Fix "RefreshIndicator.color didn't update at runtime" (#73566)

* update dependencies when widget configuration changes
parent 9a83314c
......@@ -238,6 +238,22 @@ class RefreshIndicatorState extends State<RefreshIndicator> 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();
......
......@@ -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 <Widget>[
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<RefreshProgressIndicator>(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<RefreshProgressIndicator>(find.byType(RefreshProgressIndicator)).valueColor!.value, red.withOpacity(1.0));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment