Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 5bc9340

Browse files
authored
Put stretch indicator behind m3 flag (#100234)
1 parent e6bd208 commit 5bc9340

File tree

6 files changed

+82
-13
lines changed

6 files changed

+82
-13
lines changed

packages/flutter/lib/src/material/app.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,10 @@ class MaterialApp extends StatefulWidget {
730730
/// [MaterialScrollBehavior.androidOverscrollIndicator] specifies the
731731
/// overscroll indicator that is used on [TargetPlatform.android]. When null,
732732
/// [ThemeData.androidOverscrollIndicator] is used. If also null, the default
733-
/// overscroll indicator is the [GlowingOverscrollIndicator].
733+
/// overscroll indicator is the [GlowingOverscrollIndicator]. These properties
734+
/// are deprecated. In order to use the [StretchingOverscrollIndicator], use
735+
/// the [ThemeData.useMaterial3] flag, or override
736+
/// [ScrollBehavior.buildOverscrollIndicator].
734737
///
735738
/// See also:
736739
///
@@ -745,6 +748,10 @@ class MaterialScrollBehavior extends ScrollBehavior {
745748
/// [ThemeData.androidOverscrollIndicator] is used. If also null, the default
746749
/// overscroll indicator is the [GlowingOverscrollIndicator].
747750
const MaterialScrollBehavior({
751+
@Deprecated(
752+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
753+
'This feature was deprecated after v2.13.0-0.0.pre.'
754+
)
748755
AndroidOverscrollIndicator? androidOverscrollIndicator,
749756
}) : _androidOverscrollIndicator = androidOverscrollIndicator,
750757
super(androidOverscrollIndicator: androidOverscrollIndicator);
@@ -782,9 +789,14 @@ class MaterialScrollBehavior extends ScrollBehavior {
782789
Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
783790
// When modifying this function, consider modifying the implementation in
784791
// the base class as well.
785-
final AndroidOverscrollIndicator indicator = _androidOverscrollIndicator
792+
late final AndroidOverscrollIndicator indicator;
793+
if (Theme.of(context).useMaterial3) {
794+
indicator = AndroidOverscrollIndicator.stretch;
795+
} else {
796+
indicator = _androidOverscrollIndicator
786797
?? Theme.of(context).androidOverscrollIndicator
787798
?? androidOverscrollIndicator;
799+
}
788800
switch (getPlatform(context)) {
789801
case TargetPlatform.iOS:
790802
case TargetPlatform.linux:

packages/flutter/lib/src/material/theme_data.dart

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ class ThemeData with Diagnosticable {
270270
/// * [ColorScheme.fromSeed], which is used to create a [ColorScheme] from a seed color.
271271
factory ThemeData({
272272
// GENERAL CONFIGURATION
273-
AndroidOverscrollIndicator? androidOverscrollIndicator,
274273
bool? applyElevationOverlayColor,
275274
NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
276275
Iterable<ThemeExtension<dynamic>>? extensions,
@@ -418,6 +417,11 @@ class ThemeData with Diagnosticable {
418417
'This feature was deprecated after v2.6.0-11.0.pre.',
419418
)
420419
Brightness? primaryColorBrightness,
420+
@Deprecated(
421+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
422+
'This feature was deprecated after v2.13.0-0.0.pre.'
423+
)
424+
AndroidOverscrollIndicator? androidOverscrollIndicator,
421425
}) {
422426
// GENERAL CONFIGURATION
423427
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
@@ -591,7 +595,6 @@ class ThemeData with Diagnosticable {
591595

592596
return ThemeData.raw(
593597
// GENERAL CONFIGURATION
594-
androidOverscrollIndicator: androidOverscrollIndicator,
595598
applyElevationOverlayColor: applyElevationOverlayColor,
596599
cupertinoOverrideTheme: cupertinoOverrideTheme,
597600
extensions: _themeExtensionIterableToMap(extensions),
@@ -680,6 +683,7 @@ class ThemeData with Diagnosticable {
680683
buttonColor: buttonColor,
681684
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
682685
primaryColorBrightness: primaryColorBrightness,
686+
androidOverscrollIndicator: androidOverscrollIndicator,
683687
);
684688
}
685689

@@ -695,7 +699,6 @@ class ThemeData with Diagnosticable {
695699
// operator == and in the Object.hash method and in the order of fields
696700
// in this class, and in the lerp() method.
697701
// GENERAL CONFIGURATION
698-
required this.androidOverscrollIndicator,
699702
required this.applyElevationOverlayColor,
700703
required this.cupertinoOverrideTheme,
701704
required this.extensions,
@@ -839,6 +842,11 @@ class ThemeData with Diagnosticable {
839842
'This feature was deprecated after v2.6.0-11.0.pre.',
840843
)
841844
required this.primaryColorBrightness,
845+
@Deprecated(
846+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
847+
'This feature was deprecated after v2.13.0-0.0.pre.'
848+
)
849+
required this.androidOverscrollIndicator,
842850
}) : // GENERAL CONFIGURATION
843851
assert(applyElevationOverlayColor != null),
844852
assert(extensions != null),
@@ -1031,12 +1039,19 @@ class ThemeData with Diagnosticable {
10311039
/// [MaterialScrollBehavior.androidOverscrollIndicator] is
10321040
/// [AndroidOverscrollIndicator.glow].
10331041
///
1042+
/// This property is deprecated. Use the [useMaterial3] flag instead, or
1043+
/// override [ScrollBehavior.buildOverscrollIndicator].
1044+
///
10341045
/// See also:
10351046
///
10361047
/// * [StretchingOverscrollIndicator], a material design edge effect
10371048
/// that transforms the contents of a scrollable when overscrolled.
10381049
/// * [GlowingOverscrollIndicator], an edge effect that paints a glow
10391050
/// over the contents of a scrollable when overscrolled.
1051+
@Deprecated(
1052+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
1053+
'This feature was deprecated after v2.13.0-0.0.pre.'
1054+
)
10401055
final AndroidOverscrollIndicator? androidOverscrollIndicator;
10411056

10421057
/// Apply a semi-transparent overlay color on Material surfaces to indicate
@@ -1239,6 +1254,8 @@ class ThemeData with Diagnosticable {
12391254
/// * [Material]
12401255
/// * [NavigationBar]
12411256
/// * [NavigationRail]
1257+
/// * [StretchingOverscrollIndicator], replacing the
1258+
/// [GlowingOverscrollIndicator]
12421259
///
12431260
/// See also:
12441261
///
@@ -1646,7 +1663,6 @@ class ThemeData with Diagnosticable {
16461663
/// The [brightness] value is applied to the [colorScheme].
16471664
ThemeData copyWith({
16481665
// GENERAL CONFIGURATION
1649-
AndroidOverscrollIndicator? androidOverscrollIndicator,
16501666
bool? applyElevationOverlayColor,
16511667
NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
16521668
Iterable<ThemeExtension<dynamic>>? extensions,
@@ -1791,11 +1807,15 @@ class ThemeData with Diagnosticable {
17911807
'This feature was deprecated after v2.6.0-11.0.pre.',
17921808
)
17931809
Brightness? primaryColorBrightness,
1810+
@Deprecated(
1811+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
1812+
'This feature was deprecated after v2.13.0-0.0.pre.'
1813+
)
1814+
AndroidOverscrollIndicator? androidOverscrollIndicator,
17941815
}) {
17951816
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
17961817
return ThemeData.raw(
17971818
// GENERAL CONFIGURATION
1798-
androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator,
17991819
applyElevationOverlayColor: applyElevationOverlayColor ?? this.applyElevationOverlayColor,
18001820
cupertinoOverrideTheme: cupertinoOverrideTheme ?? this.cupertinoOverrideTheme,
18011821
extensions: (extensions != null) ? _themeExtensionIterableToMap(extensions) : this.extensions,
@@ -1884,6 +1904,7 @@ class ThemeData with Diagnosticable {
18841904
buttonColor: buttonColor ?? this.buttonColor,
18851905
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel ?? this.fixTextFieldOutlineLabel,
18861906
primaryColorBrightness: primaryColorBrightness ?? this.primaryColorBrightness,
1907+
androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator,
18871908
);
18881909
}
18891910

@@ -1994,7 +2015,6 @@ class ThemeData with Diagnosticable {
19942015
// the class and in the lerp() method.
19952016
return ThemeData.raw(
19962017
// GENERAL CONFIGURATION
1997-
androidOverscrollIndicator:t < 0.5 ? a.androidOverscrollIndicator : b.androidOverscrollIndicator,
19982018
applyElevationOverlayColor:t < 0.5 ? a.applyElevationOverlayColor : b.applyElevationOverlayColor,
19992019
cupertinoOverrideTheme:t < 0.5 ? a.cupertinoOverrideTheme : b.cupertinoOverrideTheme,
20002020
extensions: _lerpThemeExtensions(a, b, t),
@@ -2083,6 +2103,7 @@ class ThemeData with Diagnosticable {
20832103
buttonColor: Color.lerp(a.buttonColor, b.buttonColor, t)!,
20842104
fixTextFieldOutlineLabel: t < 0.5 ? a.fixTextFieldOutlineLabel : b.fixTextFieldOutlineLabel,
20852105
primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness,
2106+
androidOverscrollIndicator:t < 0.5 ? a.androidOverscrollIndicator : b.androidOverscrollIndicator,
20862107
);
20872108
}
20882109

@@ -2095,7 +2116,6 @@ class ThemeData with Diagnosticable {
20952116
// the class and in the lerp() method.
20962117
return other is ThemeData &&
20972118
// GENERAL CONFIGURATION
2098-
other.androidOverscrollIndicator == androidOverscrollIndicator &&
20992119
other.applyElevationOverlayColor == applyElevationOverlayColor &&
21002120
other.cupertinoOverrideTheme == cupertinoOverrideTheme &&
21012121
mapEquals(other.extensions, extensions) &&
@@ -2183,7 +2203,8 @@ class ThemeData with Diagnosticable {
21832203
other.accentIconTheme == accentIconTheme &&
21842204
other.buttonColor == buttonColor &&
21852205
other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel &&
2186-
other.primaryColorBrightness == primaryColorBrightness;
2206+
other.primaryColorBrightness == primaryColorBrightness &&
2207+
other.androidOverscrollIndicator == androidOverscrollIndicator;
21872208
}
21882209

21892210
@override
@@ -2193,7 +2214,6 @@ class ThemeData with Diagnosticable {
21932214
// and in the order of fields in the class and in the lerp() method.
21942215
final List<Object?> values = <Object?>[
21952216
// GENERAL CONFIGURATION
2196-
androidOverscrollIndicator,
21972217
applyElevationOverlayColor,
21982218
cupertinoOverrideTheme,
21992219
hashList(extensions.keys),
@@ -2283,6 +2303,7 @@ class ThemeData with Diagnosticable {
22832303
buttonColor,
22842304
fixTextFieldOutlineLabel,
22852305
primaryColorBrightness,
2306+
androidOverscrollIndicator,
22862307
];
22872308
return Object.hashAll(values);
22882309
}
@@ -2292,7 +2313,6 @@ class ThemeData with Diagnosticable {
22922313
super.debugFillProperties(properties);
22932314
final ThemeData defaultData = ThemeData.fallback();
22942315
// GENERAL CONFIGURATION
2295-
properties.add(EnumProperty<AndroidOverscrollIndicator>('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug));
22962316
properties.add(DiagnosticsProperty<bool>('applyElevationOverlayColor', applyElevationOverlayColor, level: DiagnosticLevel.debug));
22972317
properties.add(DiagnosticsProperty<NoDefaultCupertinoThemeData>('cupertinoOverrideTheme', cupertinoOverrideTheme, defaultValue: defaultData.cupertinoOverrideTheme, level: DiagnosticLevel.debug));
22982318
properties.add(IterableProperty<ThemeExtension<dynamic>>('extensions', extensions.values, defaultValue: defaultData.extensions.values, level: DiagnosticLevel.debug));
@@ -2381,6 +2401,7 @@ class ThemeData with Diagnosticable {
23812401
properties.add(ColorProperty('buttonColor', buttonColor, defaultValue: defaultData.buttonColor, level: DiagnosticLevel.debug));
23822402
properties.add(DiagnosticsProperty<bool>('fixTextFieldOutlineLabel', fixTextFieldOutlineLabel, level: DiagnosticLevel.debug));
23832403
properties.add(EnumProperty<Brightness>('primaryColorBrightness', primaryColorBrightness, defaultValue: defaultData.primaryColorBrightness, level: DiagnosticLevel.debug));
2404+
properties.add(EnumProperty<AndroidOverscrollIndicator>('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug));
23842405
}
23852406
}
23862407

packages/flutter/lib/src/widgets/overscroll_indicator.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ class _GlowingOverscrollIndicatorPainter extends CustomPainter {
623623
/// [ScrollBehavior.androidOverscrollIndicator] is
624624
/// [AndroidOverscrollIndicator.stretch]. Otherwise, the default
625625
/// [GlowingOverscrollIndicator] is applied.
626+
/// [ScrollBehavior.androidOverscrollIndicator] is deprecated, use
627+
/// [ThemeData.useMaterial3], or override
628+
/// [ScrollBehavior.buildOverscrollIndicator] to choose the desired indicator.
626629
///
627630
/// See also:
628631
///
@@ -669,6 +672,9 @@ class StretchingOverscrollIndicator extends StatefulWidget {
669672
/// [ScrollBehavior.buildOverscrollIndicator] method when opted-in using the
670673
/// [ScrollBehavior.androidOverscrollIndicator] flag. In this case
671674
/// the child is usually the one provided as an argument to that method.
675+
/// [ScrollBehavior.androidOverscrollIndicator] is deprecated, use
676+
/// [ThemeData.useMaterial3], or override
677+
/// [ScrollBehavior.buildOverscrollIndicator] to choose the desired indicator.
672678
final Widget? child;
673679

674680
@override

packages/flutter/lib/src/widgets/scroll_configuration.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ enum AndroidOverscrollIndicator {
6262
class ScrollBehavior {
6363
/// Creates a description of how [Scrollable] widgets should behave.
6464
const ScrollBehavior({
65+
@Deprecated(
66+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
67+
'This feature was deprecated after v2.13.0-0.0.pre.'
68+
)
6569
AndroidOverscrollIndicator? androidOverscrollIndicator,
6670
}): _androidOverscrollIndicator = androidOverscrollIndicator;
6771

@@ -73,6 +77,10 @@ class ScrollBehavior {
7377
///
7478
/// * [MaterialScrollBehavior], which supports setting this property
7579
/// using [ThemeData].
80+
@Deprecated(
81+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
82+
'This feature was deprecated after v2.13.0-0.0.pre.'
83+
)
7684
AndroidOverscrollIndicator get androidOverscrollIndicator => _androidOverscrollIndicator ?? _kDefaultAndroidOverscrollIndicator;
7785
final AndroidOverscrollIndicator? _androidOverscrollIndicator;
7886

@@ -90,6 +98,10 @@ class ScrollBehavior {
9098
Set<PointerDeviceKind>? dragDevices,
9199
ScrollPhysics? physics,
92100
TargetPlatform? platform,
101+
@Deprecated(
102+
'Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. '
103+
'This feature was deprecated after v2.13.0-0.0.pre.'
104+
)
93105
AndroidOverscrollIndicator? androidOverscrollIndicator,
94106
}) {
95107
return _WrappedScrollBehavior(

packages/flutter/test/material/app_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,24 @@ void main() {
11031103
expect(find.byType(GlowingOverscrollIndicator), findsNothing);
11041104
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
11051105

1106+
testWidgets('ScrollBehavior stretch android overscroll indicator via useMaterial3 flag', (WidgetTester tester) async {
1107+
await tester.pumpWidget(MaterialApp(
1108+
theme: ThemeData(useMaterial3: true),
1109+
home: ListView(
1110+
children: const <Widget>[
1111+
SizedBox(
1112+
height: 1000.0,
1113+
width: 1000.0,
1114+
child: Text('Test'),
1115+
)
1116+
]
1117+
)
1118+
));
1119+
1120+
expect(find.byType(StretchingOverscrollIndicator), findsOneWidget);
1121+
expect(find.byType(GlowingOverscrollIndicator), findsNothing);
1122+
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
1123+
11061124
testWidgets('Overscroll indicator can be set by theme', (WidgetTester tester) async {
11071125
await tester.pumpWidget(MaterialApp(
11081126
// The current default is glowing, setting via the theme should override.

packages/flutter/test/material/theme_data_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ void main() {
999999
// List of properties must match the properties in ThemeData.hashCode()
10001000
final Set<String> expectedPropertyNames = <String>{
10011001
// GENERAL CONFIGURATION
1002-
'androidOverscrollIndicator',
10031002
'applyElevationOverlayColor',
10041003
'cupertinoOverrideTheme',
10051004
'extensions',
@@ -1088,6 +1087,7 @@ void main() {
10881087
'buttonColor',
10891088
'fixTextFieldOutlineLabel',
10901089
'primaryColorBrightness',
1090+
'androidOverscrollIndicator',
10911091
};
10921092

10931093
final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder();

0 commit comments

Comments
 (0)