Added support for elevation on refresh indicator (#154182)

Refresh Indicator Elevation:

- Added elevation to the refresh indicator using elevation attribute.
- This change improves the indicator's visibility against various background colors and enhances overall UI consistency.
- If we want to get rid of shadow effect from the indicator itself.

The refresh indicator did not provide the control over depth of the progress indicator. This change addresses that issue by adding elevation to the indicator, creating a subtle depth effect that makes it more visually prominent and provides better feedback to the user.

No breaking changes.

| Before | After |
| --- | --- |
| ![337189619-885559b5-3046-4926-aea0-66be8f5d58c8](https://github.com/user-attachments/assets/24bd5b26-c776-4131-b5ca-1054e2cc90e8) | ![337189633-5c4d2d67-0729-4d1d-86a0-1402d1ac009e](https://github.com/user-attachments/assets/02d655f6-851b-4cd5-b2ae-1c3a496f9189) |

Pre-launch Checklist
This commit is contained in:
Dishank Jindal
2024-08-30 23:20:08 +05:30
committed by GitHub
parent e48a45ff5e
commit 01e8ecaea6
2 changed files with 67 additions and 3 deletions

View File

@@ -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<RefreshIndicator>
valueColor: _valueColor,
backgroundColor: widget.backgroundColor,
strokeWidth: widget.strokeWidth,
elevation: widget.elevation,
);
final Widget cupertinoIndicator = CupertinoActivityIndicator(

View File

@@ -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 <Widget>[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<RefreshProgressIndicator>(find.byType(RefreshProgressIndicator)).elevation, 2.0);
});
testWidgets('RefreshIndicator passes custom elevation values through correctly', (WidgetTester tester) async {
for (final double elevation in <double>[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 <Widget>[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<RefreshProgressIndicator>(find.byType(RefreshProgressIndicator)).elevation, elevation);
await tester.pumpAndSettle();
}
});
}