From 018fa8c51eeab7f7c98f9cda981931cb5c69db94 Mon Sep 17 00:00:00 2001 From: Tae Hyung Kim Date: Tue, 11 Jul 2023 13:04:17 -0700 Subject: [PATCH] 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. --- .../refresh_indicator.1.dart | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/examples/api/lib/material/refresh_indicator/refresh_indicator.1.dart b/examples/api/lib/material/refresh_indicator/refresh_indicator.1.dart index aec46093c8e..c389d404ab7 100644 --- a/examples/api/lib/material/refresh_indicator/refresh_indicator.1.dart +++ b/examples/api/lib/material/refresh_indicator/refresh_indicator.1.dart @@ -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: [ - Container( + child: CustomScrollView( + slivers: [ + 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"), + ); + } + ) + ], ), ), );