From 1cff1b29b122ce22f675dec563ae74df42b21959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Sun, 8 Jun 2025 09:15:28 +0100 Subject: [PATCH 1/5] Fix infinite loop in CupertinoSliverNavigationBar collapse animation by adding bounds check for target scroll position --- packages/flutter/lib/src/cupertino/nav_bar.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 681273dda1104..2e0a992e7c13d 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -1297,7 +1297,7 @@ class _CupertinoSliverNavigationBarState extends State Date: Sun, 8 Jun 2025 09:27:02 +0100 Subject: [PATCH 2/5] Add bounds check for target scroll position in CupertinoSliverNavigationBar collapse animation --- packages/flutter/lib/src/cupertino/nav_bar.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 2e0a992e7c13d..337754015c9cf 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -1297,6 +1297,7 @@ class _CupertinoSliverNavigationBarState extends State Date: Sun, 8 Jun 2025 12:16:51 +0100 Subject: [PATCH 3/5] Add test to prevent infinite animation loop in CupertinoSliverNavigationBar --- .../flutter/test/cupertino/nav_bar_test.dart | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index 2175d8edb2a4e..4cda9d3e1cf54 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -3069,6 +3069,77 @@ void main() { expect(find.text(largeTitle), findsOneWidget); expect(find.byType(CupertinoSearchTextField), findsOneWidget); }); + + testWidgets( + 'CupertinoSliverNavigationBar does not enter infinite animation loop when target exceeds maxScrollExtent and prevents buttons from being tapped', + (WidgetTester tester) async { + setWindowToPortrait(tester); + + const double largeTitleHeight = 52.0; + + final ScrollController scrollController = ScrollController(); + addTearDown(scrollController.dispose); + + tester.view.devicePixelRatio = 1; + tester.binding.platformDispatcher.textScaleFactorTestValue = 1; + setWindowToPortrait(tester, size: const Size(402, 874)); + + int count = 0; + + await tester.pumpWidget( + CupertinoApp( + home: CustomScrollView( + controller: scrollController, + slivers: [ + const CupertinoSliverNavigationBar(largeTitle: Text('Large Title')), + SliverToBoxAdapter( + child: SizedBox( + // This height will trigger the issue if the target exceeds maxScrollExtent. + height: 805, + child: Center( + child: CupertinoButton( + child: const Text('Press me!'), + onPressed: () { + count++; + }, + ), + ), + ), + ), + ], + ), + ), + ); + + await tester.pumpAndSettle(); + + // Verify the button is present + expect(find.widgetWithText(CupertinoButton, 'Press me!'), findsOneWidget); + + // Tap the button + await tester.tap(find.widgetWithText(CupertinoButton, 'Press me!')); + await tester.pump(); // Process the tap + + // Check if the counter has increased + expect(count, 1); + + // Scroll a little over the halfway point. + final TestGesture scrollGesture = await tester.startGesture( + tester.getCenter(find.byType(Scrollable)), + ); + await scrollGesture.moveBy(const Offset(0.0, -(largeTitleHeight / 2) - 1)); + await scrollGesture.up(); + // This should not time out or throw an error. + await tester.pumpAndSettle(); + + // Tap the button + await tester.tap(find.widgetWithText(CupertinoButton, 'Press me!')); + await tester.pump(); // Process the tap + + // Check if the counter has increased + expect(count, 2); + }, + ); } class _ExpectStyles extends StatelessWidget { From 9c1faa4999b40354751bd6350efeefe3db014e76 Mon Sep 17 00:00:00 2001 From: Klemen Tusar Date: Mon, 9 Jun 2025 19:59:46 +0100 Subject: [PATCH 4/5] Update packages/flutter/test/cupertino/nav_bar_test.dart Co-authored-by: Victor Sanni --- packages/flutter/test/cupertino/nav_bar_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index 4cda9d3e1cf54..bf9ea6e78937e 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -3073,8 +3073,6 @@ void main() { testWidgets( 'CupertinoSliverNavigationBar does not enter infinite animation loop when target exceeds maxScrollExtent and prevents buttons from being tapped', (WidgetTester tester) async { - setWindowToPortrait(tester); - const double largeTitleHeight = 52.0; final ScrollController scrollController = ScrollController(); From bd375807fdca3dca26a9abfce2b5c223ecfc7a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Wed, 11 Jun 2025 20:21:41 +0100 Subject: [PATCH 5/5] Refactor nav bar test for clarity and concise counter increment logic. --- .../flutter/test/cupertino/nav_bar_test.dart | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index bf9ea6e78937e..c22673f85eacf 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -3097,9 +3097,7 @@ void main() { child: Center( child: CupertinoButton( child: const Text('Press me!'), - onPressed: () { - count++; - }, + onPressed: () => count++, ), ), ), @@ -3111,14 +3109,14 @@ void main() { await tester.pumpAndSettle(); - // Verify the button is present + // Verify the button is present. expect(find.widgetWithText(CupertinoButton, 'Press me!'), findsOneWidget); - // Tap the button + // Tap the button. await tester.tap(find.widgetWithText(CupertinoButton, 'Press me!')); - await tester.pump(); // Process the tap + await tester.pump(); - // Check if the counter has increased + // Check if the counter has increased. expect(count, 1); // Scroll a little over the halfway point. @@ -3127,14 +3125,15 @@ void main() { ); await scrollGesture.moveBy(const Offset(0.0, -(largeTitleHeight / 2) - 1)); await scrollGesture.up(); - // This should not time out or throw an error. + + // The crux of this test: this should NOT time out or throw an error. await tester.pumpAndSettle(); - // Tap the button + // Tap the button. await tester.tap(find.widgetWithText(CupertinoButton, 'Press me!')); - await tester.pump(); // Process the tap + await tester.pump(); - // Check if the counter has increased + // Check if the counter has increased. expect(count, 2); }, ); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy