Skip to content

Commit a6e17e6

Browse files
committed
feat: expose shrinkWrap of CustomScrollView
- Add shrinkWrap property to InfiniteList widget - Update documentation to reference CustomScrollView.shrinkWrap - Add tests to ensure property gets proxied and defaults to false - Update README with shrinkWrap documentation Addresses feedback from PR VeryGoodOpenSource#71
1 parent 4cadd02 commit a6e17e6

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ InfiniteList<String>(
132132
// Is set to `false` by default.
133133
reverse: false,
134134
135+
// Indicates if the extent of the ScrollView in the scrollDirection
136+
// should be determined by the contents being viewed.
137+
//
138+
// Is set to `false` by default.
139+
shrinkWrap: false,
140+
135141
// The duration with which calls to [onFetchData] will be debounced.
136142
//
137143
// Is set to a duration of 100 milliseconds by default.

lib/src/infinite_list.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class InfiniteList extends StatelessWidget {
3232
this.cacheExtent,
3333
this.debounceDuration = defaultDebounceDuration,
3434
this.reverse = false,
35+
this.shrinkWrap = false,
3536
this.isLoading = false,
3637
this.hasError = false,
3738
this.hasReachedMax = false,
@@ -77,6 +78,14 @@ class InfiniteList extends StatelessWidget {
7778
/// {@endtemplate}
7879
final bool reverse;
7980

81+
/// Indicates if the extent of the [ScrollView] in the [scrollDirection]
82+
/// should be determined by the contents being viewed.
83+
///
84+
/// See also:
85+
///
86+
/// * [CustomScrollView.shrinkWrap], for more details about this flag.
87+
final bool shrinkWrap;
88+
8089
/// {@template item_count}
8190
/// The amount of items that need to be rendered by the [itemBuilder].
8291
///
@@ -207,6 +216,7 @@ class InfiniteList extends StatelessWidget {
207216
return CustomScrollView(
208217
scrollDirection: scrollDirection,
209218
reverse: reverse,
219+
shrinkWrap: shrinkWrap,
210220
controller: scrollController,
211221
physics: physics,
212222
cacheExtent: cacheExtent,

test/infinite_list_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,36 @@ void main() {
406406
tester.widget<CustomScrollView>(find.byType(CustomScrollView));
407407
expect(customScrollView.reverse, reverse);
408408
});
409+
410+
testWidgets('shrinkWrap', (tester) async {
411+
const shrinkWrap = true;
412+
await tester.pumpApp(
413+
InfiniteList(
414+
itemCount: 10,
415+
onFetchData: emptyCallback,
416+
itemBuilder: (_, i) => Text('$i'),
417+
shrinkWrap: shrinkWrap,
418+
),
419+
);
420+
421+
final customScrollView =
422+
tester.widget<CustomScrollView>(find.byType(CustomScrollView));
423+
expect(customScrollView.shrinkWrap, shrinkWrap);
424+
});
425+
426+
testWidgets('shrinkWrap defaults to false', (tester) async {
427+
await tester.pumpApp(
428+
InfiniteList(
429+
itemCount: 10,
430+
onFetchData: emptyCallback,
431+
itemBuilder: (_, i) => Text('$i'),
432+
),
433+
);
434+
435+
final customScrollView =
436+
tester.widget<CustomScrollView>(find.byType(CustomScrollView));
437+
expect(customScrollView.shrinkWrap, false);
438+
});
409439
});
410440

411441
group('centralized properties', () {

0 commit comments

Comments
 (0)