From 5bc9340233b5c8e5d52ae9ae6b72b54f4585cc4c Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Mon, 21 Mar 2022 17:55:57 -0500 Subject: [PATCH] Put stretch indicator behind m3 flag (#100234) --- packages/flutter/lib/src/material/app.dart | 16 +++++++- .../flutter/lib/src/material/theme_data.dart | 41 ++++++++++++++----- .../lib/src/widgets/overscroll_indicator.dart | 6 +++ .../lib/src/widgets/scroll_configuration.dart | 12 ++++++ packages/flutter/test/material/app_test.dart | 18 ++++++++ .../test/material/theme_data_test.dart | 2 +- 6 files changed, 82 insertions(+), 13 deletions(-) diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index 6dd71a7450..3c890bc04f 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -730,7 +730,10 @@ class MaterialApp extends StatefulWidget { /// [MaterialScrollBehavior.androidOverscrollIndicator] specifies the /// overscroll indicator that is used on [TargetPlatform.android]. When null, /// [ThemeData.androidOverscrollIndicator] is used. If also null, the default -/// overscroll indicator is the [GlowingOverscrollIndicator]. +/// overscroll indicator is the [GlowingOverscrollIndicator]. These properties +/// are deprecated. In order to use the [StretchingOverscrollIndicator], use +/// the [ThemeData.useMaterial3] flag, or override +/// [ScrollBehavior.buildOverscrollIndicator]. /// /// See also: /// @@ -745,6 +748,10 @@ class MaterialScrollBehavior extends ScrollBehavior { /// [ThemeData.androidOverscrollIndicator] is used. If also null, the default /// overscroll indicator is the [GlowingOverscrollIndicator]. const MaterialScrollBehavior({ + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) AndroidOverscrollIndicator? androidOverscrollIndicator, }) : _androidOverscrollIndicator = androidOverscrollIndicator, super(androidOverscrollIndicator: androidOverscrollIndicator); @@ -782,9 +789,14 @@ class MaterialScrollBehavior extends ScrollBehavior { Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { // When modifying this function, consider modifying the implementation in // the base class as well. - final AndroidOverscrollIndicator indicator = _androidOverscrollIndicator + late final AndroidOverscrollIndicator indicator; + if (Theme.of(context).useMaterial3) { + indicator = AndroidOverscrollIndicator.stretch; + } else { + indicator = _androidOverscrollIndicator ?? Theme.of(context).androidOverscrollIndicator ?? androidOverscrollIndicator; + } switch (getPlatform(context)) { case TargetPlatform.iOS: case TargetPlatform.linux: diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index d83002ba82..e75f57f250 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -270,7 +270,6 @@ class ThemeData with Diagnosticable { /// * [ColorScheme.fromSeed], which is used to create a [ColorScheme] from a seed color. factory ThemeData({ // GENERAL CONFIGURATION - AndroidOverscrollIndicator? androidOverscrollIndicator, bool? applyElevationOverlayColor, NoDefaultCupertinoThemeData? cupertinoOverrideTheme, Iterable>? extensions, @@ -418,6 +417,11 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v2.6.0-11.0.pre.', ) Brightness? primaryColorBrightness, + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) + AndroidOverscrollIndicator? androidOverscrollIndicator, }) { // GENERAL CONFIGURATION cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); @@ -591,7 +595,6 @@ class ThemeData with Diagnosticable { return ThemeData.raw( // GENERAL CONFIGURATION - androidOverscrollIndicator: androidOverscrollIndicator, applyElevationOverlayColor: applyElevationOverlayColor, cupertinoOverrideTheme: cupertinoOverrideTheme, extensions: _themeExtensionIterableToMap(extensions), @@ -680,6 +683,7 @@ class ThemeData with Diagnosticable { buttonColor: buttonColor, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel, primaryColorBrightness: primaryColorBrightness, + androidOverscrollIndicator: androidOverscrollIndicator, ); } @@ -695,7 +699,6 @@ class ThemeData with Diagnosticable { // operator == and in the Object.hash method and in the order of fields // in this class, and in the lerp() method. // GENERAL CONFIGURATION - required this.androidOverscrollIndicator, required this.applyElevationOverlayColor, required this.cupertinoOverrideTheme, required this.extensions, @@ -839,6 +842,11 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v2.6.0-11.0.pre.', ) required this.primaryColorBrightness, + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) + required this.androidOverscrollIndicator, }) : // GENERAL CONFIGURATION assert(applyElevationOverlayColor != null), assert(extensions != null), @@ -1031,12 +1039,19 @@ class ThemeData with Diagnosticable { /// [MaterialScrollBehavior.androidOverscrollIndicator] is /// [AndroidOverscrollIndicator.glow]. /// + /// This property is deprecated. Use the [useMaterial3] flag instead, or + /// override [ScrollBehavior.buildOverscrollIndicator]. + /// /// See also: /// /// * [StretchingOverscrollIndicator], a material design edge effect /// that transforms the contents of a scrollable when overscrolled. /// * [GlowingOverscrollIndicator], an edge effect that paints a glow /// over the contents of a scrollable when overscrolled. + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) final AndroidOverscrollIndicator? androidOverscrollIndicator; /// Apply a semi-transparent overlay color on Material surfaces to indicate @@ -1239,6 +1254,8 @@ class ThemeData with Diagnosticable { /// * [Material] /// * [NavigationBar] /// * [NavigationRail] + /// * [StretchingOverscrollIndicator], replacing the + /// [GlowingOverscrollIndicator] /// /// See also: /// @@ -1646,7 +1663,6 @@ class ThemeData with Diagnosticable { /// The [brightness] value is applied to the [colorScheme]. ThemeData copyWith({ // GENERAL CONFIGURATION - AndroidOverscrollIndicator? androidOverscrollIndicator, bool? applyElevationOverlayColor, NoDefaultCupertinoThemeData? cupertinoOverrideTheme, Iterable>? extensions, @@ -1791,11 +1807,15 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v2.6.0-11.0.pre.', ) Brightness? primaryColorBrightness, + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) + AndroidOverscrollIndicator? androidOverscrollIndicator, }) { cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); return ThemeData.raw( // GENERAL CONFIGURATION - androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator, applyElevationOverlayColor: applyElevationOverlayColor ?? this.applyElevationOverlayColor, cupertinoOverrideTheme: cupertinoOverrideTheme ?? this.cupertinoOverrideTheme, extensions: (extensions != null) ? _themeExtensionIterableToMap(extensions) : this.extensions, @@ -1884,6 +1904,7 @@ class ThemeData with Diagnosticable { buttonColor: buttonColor ?? this.buttonColor, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel ?? this.fixTextFieldOutlineLabel, primaryColorBrightness: primaryColorBrightness ?? this.primaryColorBrightness, + androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator, ); } @@ -1994,7 +2015,6 @@ class ThemeData with Diagnosticable { // the class and in the lerp() method. return ThemeData.raw( // GENERAL CONFIGURATION - androidOverscrollIndicator:t < 0.5 ? a.androidOverscrollIndicator : b.androidOverscrollIndicator, applyElevationOverlayColor:t < 0.5 ? a.applyElevationOverlayColor : b.applyElevationOverlayColor, cupertinoOverrideTheme:t < 0.5 ? a.cupertinoOverrideTheme : b.cupertinoOverrideTheme, extensions: _lerpThemeExtensions(a, b, t), @@ -2083,6 +2103,7 @@ class ThemeData with Diagnosticable { buttonColor: Color.lerp(a.buttonColor, b.buttonColor, t)!, fixTextFieldOutlineLabel: t < 0.5 ? a.fixTextFieldOutlineLabel : b.fixTextFieldOutlineLabel, primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness, + androidOverscrollIndicator:t < 0.5 ? a.androidOverscrollIndicator : b.androidOverscrollIndicator, ); } @@ -2095,7 +2116,6 @@ class ThemeData with Diagnosticable { // the class and in the lerp() method. return other is ThemeData && // GENERAL CONFIGURATION - other.androidOverscrollIndicator == androidOverscrollIndicator && other.applyElevationOverlayColor == applyElevationOverlayColor && other.cupertinoOverrideTheme == cupertinoOverrideTheme && mapEquals(other.extensions, extensions) && @@ -2183,7 +2203,8 @@ class ThemeData with Diagnosticable { other.accentIconTheme == accentIconTheme && other.buttonColor == buttonColor && other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel && - other.primaryColorBrightness == primaryColorBrightness; + other.primaryColorBrightness == primaryColorBrightness && + other.androidOverscrollIndicator == androidOverscrollIndicator; } @override @@ -2193,7 +2214,6 @@ class ThemeData with Diagnosticable { // and in the order of fields in the class and in the lerp() method. final List values = [ // GENERAL CONFIGURATION - androidOverscrollIndicator, applyElevationOverlayColor, cupertinoOverrideTheme, hashList(extensions.keys), @@ -2283,6 +2303,7 @@ class ThemeData with Diagnosticable { buttonColor, fixTextFieldOutlineLabel, primaryColorBrightness, + androidOverscrollIndicator, ]; return Object.hashAll(values); } @@ -2292,7 +2313,6 @@ class ThemeData with Diagnosticable { super.debugFillProperties(properties); final ThemeData defaultData = ThemeData.fallback(); // GENERAL CONFIGURATION - properties.add(EnumProperty('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug)); properties.add(DiagnosticsProperty('applyElevationOverlayColor', applyElevationOverlayColor, level: DiagnosticLevel.debug)); properties.add(DiagnosticsProperty('cupertinoOverrideTheme', cupertinoOverrideTheme, defaultValue: defaultData.cupertinoOverrideTheme, level: DiagnosticLevel.debug)); properties.add(IterableProperty>('extensions', extensions.values, defaultValue: defaultData.extensions.values, level: DiagnosticLevel.debug)); @@ -2381,6 +2401,7 @@ class ThemeData with Diagnosticable { properties.add(ColorProperty('buttonColor', buttonColor, defaultValue: defaultData.buttonColor, level: DiagnosticLevel.debug)); properties.add(DiagnosticsProperty('fixTextFieldOutlineLabel', fixTextFieldOutlineLabel, level: DiagnosticLevel.debug)); properties.add(EnumProperty('primaryColorBrightness', primaryColorBrightness, defaultValue: defaultData.primaryColorBrightness, level: DiagnosticLevel.debug)); + properties.add(EnumProperty('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug)); } } diff --git a/packages/flutter/lib/src/widgets/overscroll_indicator.dart b/packages/flutter/lib/src/widgets/overscroll_indicator.dart index d0c1a19198..9c19cf46be 100644 --- a/packages/flutter/lib/src/widgets/overscroll_indicator.dart +++ b/packages/flutter/lib/src/widgets/overscroll_indicator.dart @@ -623,6 +623,9 @@ class _GlowingOverscrollIndicatorPainter extends CustomPainter { /// [ScrollBehavior.androidOverscrollIndicator] is /// [AndroidOverscrollIndicator.stretch]. Otherwise, the default /// [GlowingOverscrollIndicator] is applied. +/// [ScrollBehavior.androidOverscrollIndicator] is deprecated, use +/// [ThemeData.useMaterial3], or override +/// [ScrollBehavior.buildOverscrollIndicator] to choose the desired indicator. /// /// See also: /// @@ -669,6 +672,9 @@ class StretchingOverscrollIndicator extends StatefulWidget { /// [ScrollBehavior.buildOverscrollIndicator] method when opted-in using the /// [ScrollBehavior.androidOverscrollIndicator] flag. In this case /// the child is usually the one provided as an argument to that method. + /// [ScrollBehavior.androidOverscrollIndicator] is deprecated, use + /// [ThemeData.useMaterial3], or override + /// [ScrollBehavior.buildOverscrollIndicator] to choose the desired indicator. final Widget? child; @override diff --git a/packages/flutter/lib/src/widgets/scroll_configuration.dart b/packages/flutter/lib/src/widgets/scroll_configuration.dart index 50ef4d25d2..7b0a85b5ef 100644 --- a/packages/flutter/lib/src/widgets/scroll_configuration.dart +++ b/packages/flutter/lib/src/widgets/scroll_configuration.dart @@ -62,6 +62,10 @@ enum AndroidOverscrollIndicator { class ScrollBehavior { /// Creates a description of how [Scrollable] widgets should behave. const ScrollBehavior({ + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) AndroidOverscrollIndicator? androidOverscrollIndicator, }): _androidOverscrollIndicator = androidOverscrollIndicator; @@ -73,6 +77,10 @@ class ScrollBehavior { /// /// * [MaterialScrollBehavior], which supports setting this property /// using [ThemeData]. + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) AndroidOverscrollIndicator get androidOverscrollIndicator => _androidOverscrollIndicator ?? _kDefaultAndroidOverscrollIndicator; final AndroidOverscrollIndicator? _androidOverscrollIndicator; @@ -90,6 +98,10 @@ class ScrollBehavior { Set? dragDevices, ScrollPhysics? physics, TargetPlatform? platform, + @Deprecated( + 'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. ' + 'This feature was deprecated after v2.13.0-0.0.pre.' + ) AndroidOverscrollIndicator? androidOverscrollIndicator, }) { return _WrappedScrollBehavior( diff --git a/packages/flutter/test/material/app_test.dart b/packages/flutter/test/material/app_test.dart index c09c95d2f5..c48b374bf0 100644 --- a/packages/flutter/test/material/app_test.dart +++ b/packages/flutter/test/material/app_test.dart @@ -1103,6 +1103,24 @@ void main() { expect(find.byType(GlowingOverscrollIndicator), findsNothing); }, variant: TargetPlatformVariant.only(TargetPlatform.android)); + testWidgets('ScrollBehavior stretch android overscroll indicator via useMaterial3 flag', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: true), + home: ListView( + children: const [ + SizedBox( + height: 1000.0, + width: 1000.0, + child: Text('Test'), + ) + ] + ) + )); + + expect(find.byType(StretchingOverscrollIndicator), findsOneWidget); + expect(find.byType(GlowingOverscrollIndicator), findsNothing); + }, variant: TargetPlatformVariant.only(TargetPlatform.android)); + testWidgets('Overscroll indicator can be set by theme', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( // The current default is glowing, setting via the theme should override. diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index c44f718930..049adba491 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -999,7 +999,6 @@ void main() { // List of properties must match the properties in ThemeData.hashCode() final Set expectedPropertyNames = { // GENERAL CONFIGURATION - 'androidOverscrollIndicator', 'applyElevationOverlayColor', 'cupertinoOverrideTheme', 'extensions', @@ -1088,6 +1087,7 @@ void main() { 'buttonColor', 'fixTextFieldOutlineLabel', 'primaryColorBrightness', + 'androidOverscrollIndicator', }; final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder();