mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Flutter code sample for [RefreshIndicator].
|
/// Flutter code sample for [RefreshIndicator].
|
||||||
@ -13,8 +14,9 @@ class RefreshIndicatorExampleApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const MaterialApp(
|
return MaterialApp(
|
||||||
home: RefreshIndicatorExample(),
|
scrollBehavior: const MaterialScrollBehavior().copyWith(dragDevices: PointerDeviceKind.values.toSet()),
|
||||||
|
home: const RefreshIndicatorExample(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,17 +42,17 @@ class RefreshIndicatorExample extends StatelessWidget {
|
|||||||
// from the widget's children.
|
// from the widget's children.
|
||||||
//
|
//
|
||||||
// By default this is set to `notification.depth == 0`, which ensures
|
// 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
|
// Here setting `notification.depth == 1` triggers the refresh indicator
|
||||||
// when overscrolling the nested scroll view.
|
// when overscrolling the nested scroll view.
|
||||||
notificationPredicate: (ScrollNotification notification) {
|
notificationPredicate: (ScrollNotification notification) {
|
||||||
return notification.depth == 1;
|
return notification.depth == 1;
|
||||||
},
|
},
|
||||||
child: SingleChildScrollView(
|
child: CustomScrollView(
|
||||||
child: Column(
|
slivers: <Widget>[
|
||||||
children: <Widget>[
|
SliverToBoxAdapter(
|
||||||
Container(
|
child: Container(
|
||||||
height: 100,
|
height: 100,
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
color: Colors.pink[100],
|
color: Colors.pink[100],
|
||||||
@ -65,10 +67,12 @@ class RefreshIndicatorExample extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
),
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: Container(
|
||||||
color: Colors.green[100],
|
color: Colors.green[100],
|
||||||
|
height: 300,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
shrinkWrap: true,
|
|
||||||
itemCount: 25,
|
itemCount: 25,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return const ListTile(
|
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 New Issue
Block a user