diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index 8dc13967c1..2a1cfa80e8 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -865,8 +865,21 @@ class RefreshProgressIndicator extends CircularProgressIndicator { super.semanticsLabel, super.semanticsValue, super.strokeCap, + this.elevation = 2.0, + this.indicatorMargin = const EdgeInsets.all(4.0), + this.indicatorPadding = const EdgeInsets.all(12.0), }); + /// {@macro flutter.material.material.elevation} + final double elevation; + + /// The amount of space by which to inset the whole indicator. + /// It accommodates the [elevation] of the indicator. + final EdgeInsetsGeometry indicatorMargin; + + /// The amount of space by which to inset the inner refresh indicator. + final EdgeInsetsGeometry indicatorPadding; + /// Default stroke width. static const double defaultStrokeWidth = 2.5; @@ -913,6 +926,10 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState { // Last value received from the widget before null. double? _lastValue; + /// Force casting the widget as [RefreshProgressIndicator]. + @override + RefreshProgressIndicator get widget => super.widget as RefreshProgressIndicator; + // Always show the indeterminate version of the circular progress indicator. // // When value is non-null the sweep of the progress indicator arrow's arc @@ -973,13 +990,13 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState { child: Container( width: _indicatorSize, height: _indicatorSize, - margin: const EdgeInsets.all(4.0), // accommodate the shadow + margin: widget.indicatorMargin, child: Material( type: MaterialType.circle, color: backgroundColor, - elevation: 2.0, + elevation: widget.elevation, child: Padding( - padding: const EdgeInsets.all(12.0), + padding: widget.indicatorPadding, child: Opacity( opacity: opacity, child: Transform.rotate( diff --git a/packages/flutter/test/material/progress_indicator_test.dart b/packages/flutter/test/material/progress_indicator_test.dart index 12ec99d249..7537bf9787 100644 --- a/packages/flutter/test/material/progress_indicator_test.dart +++ b/packages/flutter/test/material/progress_indicator_test.dart @@ -1183,6 +1183,75 @@ void main() { expect(tester.getSize(find.byType(CircularProgressIndicator)), const Size(36, 36)); }); + + testWidgetsWithLeakTracking('RefreshProgressIndicator using fields correctly', (WidgetTester tester) async { + Future pumpIndicator(RefreshProgressIndicator indicator) { + return tester.pumpWidget(Theme(data: theme, child: indicator)); + } + + // With default values. + await pumpIndicator(const RefreshProgressIndicator()); + Material material = tester.widget( + find.descendant( + of: find.byType(RefreshProgressIndicator), + matching: find.byType(Material), + ), + ); + Container container = tester.widget( + find.descendant( + of: find.byType(RefreshProgressIndicator), + matching: find.byType(Container), + ), + ); + Padding padding = tester.widget( + find.descendant( + of: find.descendant( + of: find.byType(RefreshProgressIndicator), + matching: find.byType(Material), + ), + matching: find.byType(Padding), + ), + ); + expect(material.elevation, 2.0); + expect(container.margin, const EdgeInsets.all(4.0)); + expect(padding.padding, const EdgeInsets.all(12.0)); + + // With values provided. + const double testElevation = 1.0; + const EdgeInsetsGeometry testIndicatorMargin = EdgeInsets.all(6.0); + const EdgeInsetsGeometry testIndicatorPadding = EdgeInsets.all(10.0); + await pumpIndicator( + const RefreshProgressIndicator( + elevation: testElevation, + indicatorMargin: testIndicatorMargin, + indicatorPadding: testIndicatorPadding, + ), + ); + material = tester.widget( + find.descendant( + of: find.byType(RefreshProgressIndicator), + matching: find.byType(Material), + ), + ); + container = tester.widget( + find.descendant( + of: find.byType(RefreshProgressIndicator), + matching: find.byType(Container), + ), + ); + padding = tester.widget( + find.descendant( + of: find.descendant( + of: find.byType(RefreshProgressIndicator), + matching: find.byType(Material), + ), + matching: find.byType(Padding), + ), + ); + expect(material.elevation, testElevation); + expect(container.margin, testIndicatorMargin); + expect(padding.padding, testIndicatorPadding); + }); } class _RefreshProgressIndicatorGolden extends StatefulWidget {