From 533229585d7400ddfed472ddf3b5fc83ed144b37 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Mon, 19 Sep 2022 16:07:19 -0500 Subject: [PATCH] Remove deprecated ScrollBehavior.buildViewportChrome (#111715) --- packages/flutter/lib/fix_data.yaml | 33 +++++++++ packages/flutter/lib/src/cupertino/app.dart | 2 + packages/flutter/lib/src/material/app.dart | 4 +- .../lib/src/widgets/scroll_configuration.dart | 73 +++++++------------ packages/flutter/test_fixes/cupertino.dart | 6 ++ .../flutter/test_fixes/cupertino.dart.expect | 6 ++ packages/flutter/test_fixes/material.dart | 6 ++ .../flutter/test_fixes/material.dart.expect | 8 +- packages/flutter/test_fixes/widgets.dart | 4 + .../flutter/test_fixes/widgets.dart.expect | 4 + 10 files changed, 96 insertions(+), 50 deletions(-) diff --git a/packages/flutter/lib/fix_data.yaml b/packages/flutter/lib/fix_data.yaml index b908da8525e..b491b4dfc49 100644 --- a/packages/flutter/lib/fix_data.yaml +++ b/packages/flutter/lib/fix_data.yaml @@ -17,6 +17,39 @@ version: 1 transforms: + # Changes made in https://github.com/flutter/flutter/pull/78588 + - title: "Migrate to 'buildOverscrollIndicator'" + date: 2021-03-18 + element: + uris: ['widgets.dart', 'material.dart', 'cupertino.dart'] + method: 'buildViewportChrome' + inClass: 'ScrollBehavior' + changes: + - kind: 'rename' + newName: 'buildOverscrollIndicator' + + # Changes made in https://github.com/flutter/flutter/pull/78588 + - title: "Migrate to 'buildOverscrollIndicator'" + date: 2021-03-18 + element: + uris: ['material.dart'] + method: 'buildViewportChrome' + inClass: 'MaterialScrollBehavior' + changes: + - kind: 'rename' + newName: 'buildOverscrollIndicator' + + # Changes made in https://github.com/flutter/flutter/pull/78588 + - title: "Migrate to 'buildOverscrollIndicator'" + date: 2021-03-18 + element: + uris: ['cupertino.dart'] + method: 'buildViewportChrome' + inClass: 'CupertinoScrollBehavior' + changes: + - kind: 'rename' + newName: 'buildOverscrollIndicator' + # Changes made in https://github.com/flutter/flutter/pull/111706 - title: "Migrate to 'trackVisibility'" date: 2022-09-15 diff --git a/packages/flutter/lib/src/cupertino/app.dart b/packages/flutter/lib/src/cupertino/app.dart index 4413f837eb3..849c6486814 100644 --- a/packages/flutter/lib/src/cupertino/app.dart +++ b/packages/flutter/lib/src/cupertino/app.dart @@ -480,6 +480,8 @@ class CupertinoScrollBehavior extends ScrollBehavior { @override ScrollPhysics getScrollPhysics(BuildContext context) { + // When modifying this function, consider modifying the implementation in + // the base class ScrollBehavior as well. if (getPlatform(context) == TargetPlatform.macOS) { return const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast); } diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index f21db89166d..af32411d6d3 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -817,7 +817,7 @@ class MaterialScrollBehavior extends ScrollBehavior { @override Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) { // When modifying this function, consider modifying the implementation in - // the base class as well. + // the base class ScrollBehavior as well. switch (axisDirectionToAxis(details.direction)) { case Axis.horizontal: return child; @@ -841,7 +841,7 @@ class MaterialScrollBehavior extends ScrollBehavior { @override Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { // When modifying this function, consider modifying the implementation in - // the base class as well. + // the base class ScrollBehavior as well. late final AndroidOverscrollIndicator indicator; if (Theme.of(context).useMaterial3) { indicator = AndroidOverscrollIndicator.stretch; diff --git a/packages/flutter/lib/src/widgets/scroll_configuration.dart b/packages/flutter/lib/src/widgets/scroll_configuration.dart index 93366d73ad0..b462add5fef 100644 --- a/packages/flutter/lib/src/widgets/scroll_configuration.dart +++ b/packages/flutter/lib/src/widgets/scroll_configuration.dart @@ -132,45 +132,6 @@ class ScrollBehavior { /// impossible to select text in scrollable containers and is not recommended. Set get dragDevices => _kTouchLikeDeviceTypes; - /// Wraps the given widget, which scrolls in the given [AxisDirection]. - /// - /// For example, on Android, this method wraps the given widget with a - /// [GlowingOverscrollIndicator] to provide visual feedback when the user - /// overscrolls. - /// - /// This method is deprecated. Use [ScrollBehavior.buildOverscrollIndicator] - /// instead. - @Deprecated( - 'Migrate to buildOverscrollIndicator. ' - 'This feature was deprecated after v2.1.0-11.0.pre.', - ) - Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) { - switch (getPlatform(context)) { - case TargetPlatform.iOS: - case TargetPlatform.linux: - case TargetPlatform.macOS: - case TargetPlatform.windows: - return child; - case TargetPlatform.android: - switch (androidOverscrollIndicator) { - case AndroidOverscrollIndicator.stretch: - return StretchingOverscrollIndicator( - axisDirection: axisDirection, - child: child, - ); - case AndroidOverscrollIndicator.glow: - continue glow; - } - glow: - case TargetPlatform.fuchsia: - return GlowingOverscrollIndicator( - axisDirection: axisDirection, - color: _kDefaultGlowColor, - child: child, - ); - } - } - /// Applies a [RawScrollbar] to the child widget on desktop platforms. Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) { // When modifying this function, consider modifying the implementation in @@ -193,11 +154,32 @@ class ScrollBehavior { /// Applies a [GlowingOverscrollIndicator] to the child widget on /// [TargetPlatform.android] and [TargetPlatform.fuchsia]. Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { - // TODO(Piinks): Move implementation from buildViewportChrome here after - // deprecation period // When modifying this function, consider modifying the implementation in // the Material and Cupertino subclasses as well. - return buildViewportChrome(context, child, details.direction); + switch (getPlatform(context)) { + case TargetPlatform.iOS: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + return child; + case TargetPlatform.android: + switch (androidOverscrollIndicator) { + case AndroidOverscrollIndicator.stretch: + return StretchingOverscrollIndicator( + axisDirection: details.direction, + child: child, + ); + case AndroidOverscrollIndicator.glow: + continue glow; + } + glow: + case TargetPlatform.fuchsia: + return GlowingOverscrollIndicator( + axisDirection: details.direction, + color: _kDefaultGlowColor, + child: child, + ); + } } /// Specifies the type of velocity tracker to use in the descendant @@ -243,6 +225,8 @@ class ScrollBehavior { /// [BouncingScrollPhysics] on iOS and [ClampingScrollPhysics] on /// Android. ScrollPhysics getScrollPhysics(BuildContext context) { + // When modifying this function, consider modifying the implementation in + // the Material and Cupertino subclasses as well. switch (getPlatform(context)) { case TargetPlatform.iOS: return _bouncingPhysics; @@ -315,11 +299,6 @@ class _WrappedScrollBehavior implements ScrollBehavior { return child; } - @override - Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) { - return delegate.buildViewportChrome(context, child, axisDirection); - } - @override ScrollBehavior copyWith({ bool? scrollbars, diff --git a/packages/flutter/test_fixes/cupertino.dart b/packages/flutter/test_fixes/cupertino.dart index cf0b69737f0..4ea5c635a44 100644 --- a/packages/flutter/test_fixes/cupertino.dart +++ b/packages/flutter/test_fixes/cupertino.dart @@ -229,4 +229,10 @@ void main() { // Change made in https://github.com/flutter/flutter/pull/100381 TextSelectionOverlay.fadeDuration; + + // Changes made in https://github.com/flutter/flutter/pull/78588 + final ScrollBehavior scrollBehavior = ScrollBehavior(); + scrollBehavior.buildViewportChrome(context, child, axisDirection); + final CupertinoScrollBehavior cupertinoScrollBehavior = CupertinoScrollBehavior(); + cupertinoScrollBehavior.buildViewportChrome(context, child, axisDirection); } diff --git a/packages/flutter/test_fixes/cupertino.dart.expect b/packages/flutter/test_fixes/cupertino.dart.expect index 8fd9f03f5de..28ed8b9042d 100644 --- a/packages/flutter/test_fixes/cupertino.dart.expect +++ b/packages/flutter/test_fixes/cupertino.dart.expect @@ -229,4 +229,10 @@ void main() { // Change made in https://github.com/flutter/flutter/pull/100381 SelectionOverlay.fadeDuration; + + // Changes made in https://github.com/flutter/flutter/pull/78588 + final ScrollBehavior scrollBehavior = ScrollBehavior(); + scrollBehavior.buildOverscrollIndicator(context, child, axisDirection); + final CupertinoScrollBehavior cupertinoScrollBehavior = CupertinoScrollBehavior(); + cupertinoScrollBehavior.buildOverscrollIndicator(context, child, axisDirection); } diff --git a/packages/flutter/test_fixes/material.dart b/packages/flutter/test_fixes/material.dart index c0660ec0bb3..ae88f25bb2b 100644 --- a/packages/flutter/test_fixes/material.dart +++ b/packages/flutter/test_fixes/material.dart @@ -695,6 +695,12 @@ void main() { themeData = ThemeData.raw(bottomAppBarColor: Colors.green); themeData = ThemeData.copyWith(bottomAppBarColor: Colors.green); + // Changes made in https://github.com/flutter/flutter/pull/78588 + final ScrollBehavior scrollBehavior = ScrollBehavior(); + scrollBehavior.buildViewportChrome(context, child, axisDirection); + final MaterialScrollBehavior materialScrollBehavior = MaterialScrollBehavior(); + materialScrollBehavior.buildViewportChrome(context, child, axisDirection); + // Changes made in https://github.com/flutter/flutter/pull/111706 Scrollbar scrollbar = Scrollbar(showTrackOnHover: true); bool nowShowing = scrollbar.showTrackOnHover; diff --git a/packages/flutter/test_fixes/material.dart.expect b/packages/flutter/test_fixes/material.dart.expect index 445f6540da3..00f404e1b46 100644 --- a/packages/flutter/test_fixes/material.dart.expect +++ b/packages/flutter/test_fixes/material.dart.expect @@ -889,7 +889,7 @@ void main() { // Changes made in https://github.com/flutter/flutter/pull/110162 ThemeData themeData = ThemeData(); - themeData = ThemeData(colorScheme: ColorScheme(error: Colors.red).copyWith(background: Colors.grey)); + themeData = ThemeData(colorScheme: ColorScheme(background: Colors.grey).copyWith(error: Colors.red)); themeData = ThemeData.raw(colorScheme: ColorScheme(error: Colors.red).copyWith(background: Colors.grey)); themeData = themeData.copyWith(colorScheme: ColorScheme(error: Colors.red).copyWith(background: Colors.grey)); @@ -899,6 +899,12 @@ void main() { themeData = ThemeData.raw(bottomAppBarTheme: BottomAppBarTheme(color: Colors.green)); themeData = ThemeData.copyWith(bottomAppBarTheme: BottomAppBarTheme(color: Colors.green)); + // Changes made in https://github.com/flutter/flutter/pull/78588 + final ScrollBehavior scrollBehavior = ScrollBehavior(); + scrollBehavior.buildOverscrollIndicator(context, child, axisDirection); + final MaterialScrollBehavior materialScrollBehavior = MaterialScrollBehavior(); + materialScrollBehavior.buildOverscrollIndicator(context, child, axisDirection); + // Changes made in https://github.com/flutter/flutter/pull/111706 Scrollbar scrollbar = Scrollbar(trackVisibility: true); bool nowShowing = scrollbar.trackVisibility; diff --git a/packages/flutter/test_fixes/widgets.dart b/packages/flutter/test_fixes/widgets.dart index b1c489ef395..0ef820ac774 100644 --- a/packages/flutter/test_fixes/widgets.dart +++ b/packages/flutter/test_fixes/widgets.dart @@ -184,4 +184,8 @@ void main() { // Change made in https://github.com/flutter/flutter/pull/100381 TextSelectionOverlay.fadeDuration; + + // Changes made in https://github.com/flutter/flutter/pull/78588 + final ScrollBehavior scrollBehavior = ScrollBehavior(); + scrollBehavior.buildViewportChrome(context, child, axisDirection); } diff --git a/packages/flutter/test_fixes/widgets.dart.expect b/packages/flutter/test_fixes/widgets.dart.expect index 3595b1ab2ba..4be0c8040e9 100644 --- a/packages/flutter/test_fixes/widgets.dart.expect +++ b/packages/flutter/test_fixes/widgets.dart.expect @@ -184,4 +184,8 @@ void main() { // Change made in https://github.com/flutter/flutter/pull/100381 SelectionOverlay.fadeDuration; + + // Changes made in https://github.com/flutter/flutter/pull/78588 + final ScrollBehavior scrollBehavior = ScrollBehavior(); + scrollBehavior.buildOverscrollIndicator(context, child, axisDirection); }