Unverified Commit 792e7ce8 authored by Devon Carew's avatar Devon Carew Committed by GitHub

add an assert to validate the RefreshIndicator.onRefresh result (#13198)

* add an assert to validate the RefreshIndicator.onRefresh result

* add a test for RefreshIndicator.onRefresh assert

* switch to using FlutterError.reportError, FlutterErrorDetails, and FlutterError
parent c182e0e5
......@@ -326,7 +326,22 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
_mode = _RefreshIndicatorMode.refresh;
});
widget.onRefresh().whenComplete(() {
final Future<Null> refreshResult = widget.onRefresh();
assert(() {
if (refreshResult == null)
FlutterError.reportError(new FlutterErrorDetails(
exception: new FlutterError(
'The onRefresh callback returned null.\n'
'The RefreshIndicator onRefresh callback must return a Future.'
),
context: 'when calling onRefresh',
library: 'material library',
));
return true;
});
if (refreshResult == null)
return;
refreshResult.whenComplete(() {
if (mounted && _mode == _RefreshIndicatorMode.refresh) {
completer.complete();
_dismiss(_RefreshIndicatorMode.done);
......
......@@ -46,7 +46,7 @@ void main() {
await tester.pump(const Duration(seconds: 1)); // finish the indicator hide animation
expect(refreshCalled, true);
});
testWidgets('Refresh Indicator - nested', (WidgetTester tester) async {
refreshCalled = false;
await tester.pumpWidget(
......@@ -349,4 +349,33 @@ void main() {
expect(completed1, true);
expect(completed2, true);
});
testWidgets('RefreshIndicator - onRefresh asserts', (WidgetTester tester) async {
refreshCalled = false;
await tester.pumpWidget(
new MaterialApp(
home: new RefreshIndicator(
onRefresh: () {
refreshCalled = true;
// Missing a returned Future value here.
},
child: new ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: <String>['A', 'B', 'C', 'D', 'E', 'F'].map((String item) {
return new SizedBox(
height: 200.0,
child: new Text(item),
);
}).toList(),
),
),
),
);
await tester.fling(find.text('A'), const Offset(0.0, 300.0), 1000.0);
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the scroll animation
expect(refreshCalled, true);
expect(tester.takeException(), isFlutterError);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment