🚀 Add more fields to RefreshProgressIndicator (#135207)

Resolves #134494
This commit is contained in:
Alex Li 2023-09-29 02:21:58 +08:00 committed by GitHub
parent 6cde5da5ea
commit 4ed9ab8b23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 3 deletions

View file

@ -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(

View file

@ -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<void> 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 {