Skip to content

Commit 4ed9ab8

Browse files
authored
🚀 Add more fields to RefreshProgressIndicator (#135207)
Resolves #134494
1 parent 6cde5da commit 4ed9ab8

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

packages/flutter/lib/src/material/progress_indicator.dart

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,21 @@ class RefreshProgressIndicator extends CircularProgressIndicator {
865865
super.semanticsLabel,
866866
super.semanticsValue,
867867
super.strokeCap,
868+
this.elevation = 2.0,
869+
this.indicatorMargin = const EdgeInsets.all(4.0),
870+
this.indicatorPadding = const EdgeInsets.all(12.0),
868871
});
869872

873+
/// {@macro flutter.material.material.elevation}
874+
final double elevation;
875+
876+
/// The amount of space by which to inset the whole indicator.
877+
/// It accommodates the [elevation] of the indicator.
878+
final EdgeInsetsGeometry indicatorMargin;
879+
880+
/// The amount of space by which to inset the inner refresh indicator.
881+
final EdgeInsetsGeometry indicatorPadding;
882+
870883
/// Default stroke width.
871884
static const double defaultStrokeWidth = 2.5;
872885

@@ -913,6 +926,10 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState {
913926
// Last value received from the widget before null.
914927
double? _lastValue;
915928

929+
/// Force casting the widget as [RefreshProgressIndicator].
930+
@override
931+
RefreshProgressIndicator get widget => super.widget as RefreshProgressIndicator;
932+
916933
// Always show the indeterminate version of the circular progress indicator.
917934
//
918935
// When value is non-null the sweep of the progress indicator arrow's arc
@@ -973,13 +990,13 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState {
973990
child: Container(
974991
width: _indicatorSize,
975992
height: _indicatorSize,
976-
margin: const EdgeInsets.all(4.0), // accommodate the shadow
993+
margin: widget.indicatorMargin,
977994
child: Material(
978995
type: MaterialType.circle,
979996
color: backgroundColor,
980-
elevation: 2.0,
997+
elevation: widget.elevation,
981998
child: Padding(
982-
padding: const EdgeInsets.all(12.0),
999+
padding: widget.indicatorPadding,
9831000
child: Opacity(
9841001
opacity: opacity,
9851002
child: Transform.rotate(

packages/flutter/test/material/progress_indicator_test.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,75 @@ void main() {
11831183

11841184
expect(tester.getSize(find.byType(CircularProgressIndicator)), const Size(36, 36));
11851185
});
1186+
1187+
testWidgetsWithLeakTracking('RefreshProgressIndicator using fields correctly', (WidgetTester tester) async {
1188+
Future<void> pumpIndicator(RefreshProgressIndicator indicator) {
1189+
return tester.pumpWidget(Theme(data: theme, child: indicator));
1190+
}
1191+
1192+
// With default values.
1193+
await pumpIndicator(const RefreshProgressIndicator());
1194+
Material material = tester.widget(
1195+
find.descendant(
1196+
of: find.byType(RefreshProgressIndicator),
1197+
matching: find.byType(Material),
1198+
),
1199+
);
1200+
Container container = tester.widget(
1201+
find.descendant(
1202+
of: find.byType(RefreshProgressIndicator),
1203+
matching: find.byType(Container),
1204+
),
1205+
);
1206+
Padding padding = tester.widget(
1207+
find.descendant(
1208+
of: find.descendant(
1209+
of: find.byType(RefreshProgressIndicator),
1210+
matching: find.byType(Material),
1211+
),
1212+
matching: find.byType(Padding),
1213+
),
1214+
);
1215+
expect(material.elevation, 2.0);
1216+
expect(container.margin, const EdgeInsets.all(4.0));
1217+
expect(padding.padding, const EdgeInsets.all(12.0));
1218+
1219+
// With values provided.
1220+
const double testElevation = 1.0;
1221+
const EdgeInsetsGeometry testIndicatorMargin = EdgeInsets.all(6.0);
1222+
const EdgeInsetsGeometry testIndicatorPadding = EdgeInsets.all(10.0);
1223+
await pumpIndicator(
1224+
const RefreshProgressIndicator(
1225+
elevation: testElevation,
1226+
indicatorMargin: testIndicatorMargin,
1227+
indicatorPadding: testIndicatorPadding,
1228+
),
1229+
);
1230+
material = tester.widget(
1231+
find.descendant(
1232+
of: find.byType(RefreshProgressIndicator),
1233+
matching: find.byType(Material),
1234+
),
1235+
);
1236+
container = tester.widget(
1237+
find.descendant(
1238+
of: find.byType(RefreshProgressIndicator),
1239+
matching: find.byType(Container),
1240+
),
1241+
);
1242+
padding = tester.widget(
1243+
find.descendant(
1244+
of: find.descendant(
1245+
of: find.byType(RefreshProgressIndicator),
1246+
matching: find.byType(Material),
1247+
),
1248+
matching: find.byType(Padding),
1249+
),
1250+
);
1251+
expect(material.elevation, testElevation);
1252+
expect(container.margin, testIndicatorMargin);
1253+
expect(padding.padding, testIndicatorPadding);
1254+
});
11861255
}
11871256

11881257
class _RefreshProgressIndicatorGolden extends StatefulWidget {

0 commit comments

Comments
 (0)