mirror of
https://github.com/flutter/flutter
synced 2024-10-01 14:04:10 +00:00
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:
parent
cc180e214e
commit
018fa8c51e
|
@ -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"),
|
||||
);
|
||||
}
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue