Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Add more fields to RefreshProgressIndicator #135207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions packages/flutter/lib/src/material/progress_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Comment on lines 929 to 931
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting solution


// Always show the indeterminate version of the circular progress indicator.
//
// When value is non-null the sweep of the progress indicator arrow's arc
Expand Down Expand Up @@ -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(
Expand Down
69 changes: 69 additions & 0 deletions packages/flutter/test/material/progress_indicator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down