Refactor refresh_indicator.1.dart to not use shrinkwrap (#129377)

This PR changes the example app into a custom scrollview with three slivers. The middle sliver has a nested scrollview of height 300 and only this nested sliver can trigger the refresh indicator.

Fixes https://github.com/flutter/flutter/issues/116237.
This commit is contained in:
Tae Hyung Kim 2023-07-11 13:04:17 -07:00 committed by GitHub
parent cc180e214e
commit 018fa8c51e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
/// Flutter code sample for [RefreshIndicator].
@ -13,8 +14,9 @@ class RefreshIndicatorExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: RefreshIndicatorExample(),
return MaterialApp(
scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: PointerDeviceKind.values.toSet()),
home: const RefreshIndicatorExample(),
);
}
}
@ -40,17 +42,17 @@ class RefreshIndicatorExample extends StatelessWidget {
// from the widget's children.
//
// By default this is set to `notification.depth == 0`, which ensures
// the only the scroll notifications from the first child are listened to.
// the only the scroll notifications from the first scroll view are listened to.
//
// Here setting `notification.depth == 1` triggers the refresh indicator
// when overscrolling the nested scroll view.
notificationPredicate: (ScrollNotification notification) {
return notification.depth == 1;
},
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
child: CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: Container(
height: 100,
alignment: Alignment.center,
color: Colors.pink[100],
@ -65,10 +67,12 @@ class RefreshIndicatorExample extends StatelessWidget {
],
),
),
Container(
),
SliverToBoxAdapter(
child: Container(
color: Colors.green[100],
height: 300,
child: ListView.builder(
shrinkWrap: true,
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return const ListTile(
@ -78,8 +82,17 @@ class RefreshIndicatorExample extends StatelessWidget {
},
),
),
],
),
),
SliverList.builder(
itemCount: 20,
itemBuilder: (BuildContext context, int index) {
return const ListTile(
title: Text('Pull down here'),
subtitle: Text("Refresh indicator won't trigger"),
);
}
)
],
),
),
);