From 08ee37e1c19d8c2d22f3335fbb64e8482037dbe9 Mon Sep 17 00:00:00 2001 From: Ayush Bherwani Date: Tue, 31 Mar 2020 01:26:06 +0530 Subject: [PATCH] [RefreshIndicator] adds strokeWidth parameter to RefreshIndicator (#53344) --- .../lib/src/material/refresh_indicator.dart | 8 ++ .../test/material/refresh_indicator_test.dart | 75 ++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/refresh_indicator.dart b/packages/flutter/lib/src/material/refresh_indicator.dart index 85212839c4..2f2ae8e612 100644 --- a/packages/flutter/lib/src/material/refresh_indicator.dart +++ b/packages/flutter/lib/src/material/refresh_indicator.dart @@ -106,9 +106,11 @@ class RefreshIndicator extends StatefulWidget { this.notificationPredicate = defaultScrollNotificationPredicate, this.semanticsLabel, this.semanticsValue, + this.strokeWidth = 2.0 }) : assert(child != null), assert(onRefresh != null), assert(notificationPredicate != null), + assert(strokeWidth != null), super(key: key); /// The widget below this widget in the tree. @@ -153,6 +155,11 @@ class RefreshIndicator extends StatefulWidget { /// {@macro flutter.material.progressIndicator.semanticsValue} final String semanticsValue; + /// Defines `strokeWidth` for `RefreshIndicator`. + /// + /// By default, the value of `strokeWidth` is 2.0 pixels. + final double strokeWidth; + @override RefreshIndicatorState createState() => RefreshIndicatorState(); } @@ -462,6 +469,7 @@ class RefreshIndicatorState extends State with TickerProviderS value: showIndeterminateIndicator ? null : _value.value, valueColor: _valueColor, backgroundColor: widget.backgroundColor, + strokeWidth: widget.strokeWidth, ); }, ), diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index 17a5da2714..26fed9f48f 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -455,4 +455,77 @@ void main() { expect(layoutCount, 1); }); -} \ No newline at end of file + + testWidgets('strokeWidth cannot be null in RefreshIndicator', (WidgetTester tester) async { + try { + await tester.pumpWidget( + MaterialApp( + home: RefreshIndicator( + onRefresh: () async {}, + strokeWidth: null, + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: ['A', 'B', 'C', 'D', 'E', 'F'].map((String item) { + return SizedBox( + height: 200.0, + child: Text(item), + ); + }).toList(), + ), + ), + ) + ); + } on AssertionError catch(_) { + return; + } + fail('The assertion was not thrown when strokeWidth was null'); + }); + + testWidgets('RefreshIndicator responds to strokeWidth', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: RefreshIndicator( + onRefresh: () async {}, + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: ['A', 'B', 'C', 'D', 'E', 'F'].map((String item) { + return SizedBox( + height: 200.0, + child: Text(item), + ); + }).toList(), + ), + ), + ) + ); + + //By default the value of strokeWidth is 2.0 + expect( + tester.widget(find.byType(RefreshIndicator)).strokeWidth, + 2.0, + ); + + await tester.pumpWidget( + MaterialApp( + home: RefreshIndicator( + onRefresh: () async {}, + strokeWidth: 4.0, + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: ['A', 'B', 'C', 'D', 'E', 'F'].map((String item) { + return SizedBox( + height: 200.0, + child: Text(item), + ); + }).toList(), + ), + ), + ) + ); + + expect( + tester.widget(find.byType(RefreshIndicator)).strokeWidth, + 4.0, + ); + }); +}