diff --git a/packages/flutter/lib/src/material/refresh_indicator.dart b/packages/flutter/lib/src/material/refresh_indicator.dart index 4b5d42222c..11d3268069 100644 --- a/packages/flutter/lib/src/material/refresh_indicator.dart +++ b/packages/flutter/lib/src/material/refresh_indicator.dart @@ -159,8 +159,10 @@ class RefreshIndicator extends StatefulWidget { this.semanticsValue, this.strokeWidth = RefreshProgressIndicator.defaultStrokeWidth, this.triggerMode = RefreshIndicatorTriggerMode.onEdge, + this.elevation = 2.0, }) : _indicatorType = _IndicatorType.material, - onStatusChange = null; + onStatusChange = null, + assert(elevation >= 0.0); /// Creates an adaptive [RefreshIndicator] based on whether the target /// platform is iOS or macOS, following Material design's @@ -191,8 +193,10 @@ class RefreshIndicator extends StatefulWidget { this.semanticsValue, this.strokeWidth = RefreshProgressIndicator.defaultStrokeWidth, this.triggerMode = RefreshIndicatorTriggerMode.onEdge, + this.elevation = 2.0, }) : _indicatorType = _IndicatorType.adaptive, - onStatusChange = null; + onStatusChange = null, + assert(elevation >= 0.0); /// Creates a [RefreshIndicator] with no spinner and calls `onRefresh` when /// successfully armed by a drag event. @@ -207,6 +211,7 @@ class RefreshIndicator extends StatefulWidget { this.semanticsLabel, this.semanticsValue, this.triggerMode = RefreshIndicatorTriggerMode.onEdge, + this.elevation = 2.0, }) : _indicatorType = _IndicatorType.noSpinner, // The following parameters aren't used because [_IndicatorType.noSpinner] is being used, // which involves showing no spinner, hence the following parameters are useless since @@ -215,7 +220,8 @@ class RefreshIndicator extends StatefulWidget { edgeOffset = 0.0, color = null, backgroundColor = null, - strokeWidth = 0.0; + strokeWidth = 0.0, + assert(elevation >= 0.0); /// The widget below this widget in the tree. /// @@ -305,6 +311,11 @@ class RefreshIndicator extends StatefulWidget { /// Defaults to [RefreshIndicatorTriggerMode.onEdge]. final RefreshIndicatorTriggerMode triggerMode; + /// Defines the elevation of the underlying [RefreshIndicator]. + /// + /// Defaults to 2.0. + final double elevation; + @override RefreshIndicatorState createState() => RefreshIndicatorState(); } @@ -681,6 +692,7 @@ class RefreshIndicatorState extends State valueColor: _valueColor, backgroundColor: widget.backgroundColor, strokeWidth: widget.strokeWidth, + elevation: widget.elevation, ); final Widget cupertinoIndicator = CupertinoActivityIndicator( diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index c0e24ccdfe..f7ccca76be 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -1261,4 +1261,56 @@ void main() { await testColor(color); } }); + + testWidgets('RefreshIndicator passes the default elevation through correctly', (WidgetTester tester) async { + final AnimationController positionController = AnimationController(vsync: const TestVSync()); + addTearDown(positionController.dispose); + + await tester.pumpWidget( + MaterialApp( + home: RefreshIndicator( + onRefresh: refresh, + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: const [Text('X')], + ), + ), + ), + ); + + final double maxPosition = tester.view.physicalSize.height / tester.view.devicePixelRatio * 0.25; + const double position = 50.0; + await tester.fling(find.text('X'), const Offset(0.0, position), 1.0); + await tester.pump(); + positionController.value = position / maxPosition; + expect(tester.widget(find.byType(RefreshProgressIndicator)).elevation, 2.0); + }); + + testWidgets('RefreshIndicator passes custom elevation values through correctly', (WidgetTester tester) async { + for (final double elevation in [0.0, 2.0]) { + final AnimationController positionController = AnimationController(vsync: const TestVSync()); + addTearDown(positionController.dispose); + + await tester.pumpWidget( + MaterialApp( + home: RefreshIndicator( + elevation: elevation, + onRefresh: refresh, + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: const [Text('X')], + ), + ), + ), + ); + + final double maxPosition = tester.view.physicalSize.height / tester.view.devicePixelRatio * 0.25; + const double position = 50.0; + await tester.fling(find.text('X'), const Offset(0.0, position), 1.0); + await tester.pump(); + positionController.value = position / maxPosition; + expect(tester.widget(find.byType(RefreshProgressIndicator)).elevation, elevation); + await tester.pumpAndSettle(); + } + }); }