Unverified Commit a75743e8 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Revert "Re-land reverse case for AppBar scrolled under" (#102580)

parent 6132b86d
...@@ -767,34 +767,18 @@ class _AppBarState extends State<AppBar> { ...@@ -767,34 +767,18 @@ class _AppBarState extends State<AppBar> {
} }
void _handleScrollNotification(ScrollNotification notification) { void _handleScrollNotification(ScrollNotification notification) {
if (notification is ScrollUpdateNotification) {
final bool oldScrolledUnder = _scrolledUnder; final bool oldScrolledUnder = _scrolledUnder;
final ScrollMetrics metrics = notification.metrics; _scrolledUnder = notification.depth == 0
&& notification.metrics.extentBefore > 0
if (notification.depth != 0) { && notification.metrics.axis == Axis.vertical;
_scrolledUnder = false;
} else {
switch (metrics.axisDirection) {
case AxisDirection.up:
// Scroll view is reversed
_scrolledUnder = metrics.extentAfter > 0;
break;
case AxisDirection.down:
_scrolledUnder = metrics.extentBefore > 0;
break;
case AxisDirection.right:
case AxisDirection.left:
// Scrolled under is only supported in the vertical axis.
_scrolledUnder = false;
break;
}
}
if (_scrolledUnder != oldScrolledUnder) { if (_scrolledUnder != oldScrolledUnder) {
setState(() { setState(() {
// React to a change in MaterialState.scrolledUnder // React to a change in MaterialState.scrolledUnder
}); });
} }
} }
}
Color _resolveColor(Set<MaterialState> states, Color? widgetColor, Color? themeColor, Color defaultColor) { Color _resolveColor(Set<MaterialState> states, Color? widgetColor, Color? themeColor, Color defaultColor) {
return MaterialStateProperty.resolveAs<Color?>(widgetColor, states) return MaterialStateProperty.resolveAs<Color?>(widgetColor, states)
......
...@@ -9,7 +9,6 @@ import 'package:flutter/foundation.dart'; ...@@ -9,7 +9,6 @@ import 'package:flutter/foundation.dart';
import 'framework.dart'; import 'framework.dart';
import 'notification_listener.dart'; import 'notification_listener.dart';
import 'scroll_notification.dart'; import 'scroll_notification.dart';
import 'scroll_position.dart';
/// A [ScrollNotification] listener for [ScrollNotificationObserver]. /// A [ScrollNotification] listener for [ScrollNotificationObserver].
/// ///
...@@ -152,18 +151,7 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver> ...@@ -152,18 +151,7 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// A ScrollMetricsNotification allows listeners to be notified for an return NotificationListener<ScrollNotification>(
// initial state, as well as if the content dimensions change without
// scrolling.
return NotificationListener<ScrollMetricsNotification>(
onNotification: (ScrollMetricsNotification notification) {
_notifyListeners(_ConvertedScrollMetricsNotification(
metrics: notification.metrics,
context: notification.context,
));
return false;
},
child: NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) { onNotification: (ScrollNotification notification) {
_notifyListeners(notification); _notifyListeners(notification);
return false; return false;
...@@ -172,7 +160,6 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver> ...@@ -172,7 +160,6 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
scrollNotificationObserverState: this, scrollNotificationObserverState: this,
child: widget.child, child: widget.child,
), ),
),
); );
} }
...@@ -183,10 +170,3 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver> ...@@ -183,10 +170,3 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
super.dispose(); super.dispose();
} }
} }
class _ConvertedScrollMetricsNotification extends ScrollNotification {
_ConvertedScrollMetricsNotification({
required super.metrics,
required super.context,
});
}
...@@ -2567,63 +2567,47 @@ void main() { ...@@ -2567,63 +2567,47 @@ void main() {
expect(actionIconTheme.color, foregroundColor); expect(actionIconTheme.color, foregroundColor);
}); });
group('MaterialStateColor scrolledUnder', () { testWidgets('SliverAppBar.backgroundColor MaterialStateColor scrolledUnder', (WidgetTester tester) async {
const double collapsedHeight = kToolbarHeight; const double collapsedHeight = kToolbarHeight;
const double expandedHeight = 200.0; const double expandedHeight = 200.0;
const Color scrolledColor = Color(0xff00ff00); const Color scrolledColor = Color(0xff00ff00);
const Color defaultColor = Color(0xff0000ff); const Color defaultColor = Color(0xff0000ff);
Finder findAppBarMaterial() { await tester.pumpWidget(
return find.descendant(of: find.byType(AppBar), matching: find.byType(Material)).first; MaterialApp(
}
Color? getAppBarBackgroundColor(WidgetTester tester) {
return tester.widget<Material>(findAppBarMaterial()).color;
}
group('SliverAppBar', () {
Widget _buildSliverApp({
required double contentHeight,
bool reverse = false,
bool includeFlexibleSpace = false,
}) {
return MaterialApp(
home: Scaffold( home: Scaffold(
body: CustomScrollView( body: CustomScrollView(
reverse: reverse,
slivers: <Widget>[ slivers: <Widget>[
SliverAppBar( SliverAppBar(
elevation: 0, elevation: 0,
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) { backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.scrolledUnder) return states.contains(MaterialState.scrolledUnder) ? scrolledColor : defaultColor;
? scrolledColor
: defaultColor;
}), }),
expandedHeight: expandedHeight, expandedHeight: expandedHeight,
pinned: true, pinned: true,
flexibleSpace: includeFlexibleSpace
? const FlexibleSpaceBar(title: Text('SliverAppBar'))
: null,
), ),
SliverList( SliverList(
delegate: SliverChildListDelegate( delegate: SliverChildListDelegate(
<Widget>[ <Widget>[
Container(height: contentHeight, color: Colors.teal), Container(height: 1200.0, color: Colors.teal),
], ],
), ),
), ),
], ],
), ),
), ),
),
); );
Finder findAppBarMaterial() {
return find.descendant(of: find.byType(AppBar), matching: find.byType(Material));
} }
testWidgets('backgroundColor', (WidgetTester tester) async { Color? getAppBarBackgroundColor() {
await tester.pumpWidget( return tester.widget<Material>(findAppBarMaterial()).color;
_buildSliverApp(contentHeight: 1200.0) }
);
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight); expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0)); TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
...@@ -2631,7 +2615,7 @@ void main() { ...@@ -2631,7 +2615,7 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor); expect(getAppBarBackgroundColor(), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, collapsedHeight); expect(tester.getSize(findAppBarMaterial()).height, collapsedHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0)); gesture = await tester.startGesture(const Offset(50.0, 300.0));
...@@ -2639,168 +2623,107 @@ void main() { ...@@ -2639,168 +2623,107 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight); expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
}); });
testWidgets('backgroundColor with FlexibleSpace', (WidgetTester tester) async { testWidgets('SliverAppBar.backgroundColor with FlexibleSpace MaterialStateColor scrolledUnder', (WidgetTester tester) async {
await tester.pumpWidget( const double collapsedHeight = kToolbarHeight;
_buildSliverApp(contentHeight: 1200.0, includeFlexibleSpace: true) const double expandedHeight = 200.0;
); const Color scrolledColor = Color(0xff00ff00);
const Color defaultColor = Color(0xff0000ff);
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, -expandedHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, collapsedHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0));
await gesture.moveBy(const Offset(0.0, expandedHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
});
testWidgets('backgroundColor - reverse', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
_buildSliverApp(contentHeight: 1200.0, reverse: true) MaterialApp(
home: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
elevation: 0,
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.scrolledUnder) ? scrolledColor : defaultColor;
}),
expandedHeight: expandedHeight,
pinned: true,
flexibleSpace: const FlexibleSpaceBar(
title: Text('SliverAppBar'),
),
),
SliverList(
delegate: SliverChildListDelegate(
<Widget>[
Container(height: 1200.0, color: Colors.teal),
],
),
),
],
),
),
),
); );
expect(getAppBarBackgroundColor(tester), defaultColor); Finder findAppBarMaterial() {
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight); // There are 2 Material widgets below AppBar. The second is only added if
// flexibleSpace is non-null.
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0)); return find.descendant(of: find.byType(AppBar), matching: find.byType(Material)).first;
await gesture.moveBy(const Offset(0.0, expandedHeight)); }
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, collapsedHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0));
await gesture.moveBy(const Offset(0.0, -expandedHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
});
testWidgets('backgroundColor with FlexibleSpace - reverse', (WidgetTester tester) async { Color? getAppBarBackgroundColor() {
await tester.pumpWidget( return tester.widget<Material>(findAppBarMaterial()).color;
_buildSliverApp( }
contentHeight: 1200.0,
reverse: true,
includeFlexibleSpace: true,
)
);
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight); expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0)); TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, expandedHeight)); await gesture.moveBy(const Offset(0.0, -expandedHeight));
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor); expect(getAppBarBackgroundColor(), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, collapsedHeight); expect(tester.getSize(findAppBarMaterial()).height, collapsedHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0)); gesture = await tester.startGesture(const Offset(50.0, 300.0));
await gesture.moveBy(const Offset(0.0, -expandedHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
});
testWidgets('backgroundColor - not triggered in reverse for short content', (WidgetTester tester) async {
await tester.pumpWidget(
_buildSliverApp(contentHeight: 200, reverse: true)
);
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
final TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, expandedHeight)); await gesture.moveBy(const Offset(0.0, expandedHeight));
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight); expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
}); });
testWidgets('backgroundColor with FlexibleSpace - not triggered in reverse for short content', (WidgetTester tester) async { testWidgets('AppBar.backgroundColor MaterialStateColor scrolledUnder', (WidgetTester tester) async {
await tester.pumpWidget( const Color scrolledColor = Color(0xff00ff00);
_buildSliverApp( const Color defaultColor = Color(0xff0000ff);
contentHeight: 200,
reverse: true,
includeFlexibleSpace: true,
)
);
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
final TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, expandedHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, expandedHeight);
});
});
group('AppBar', () { await tester.pumpWidget(
Widget _buildAppBar({ MaterialApp(
required double contentHeight,
bool reverse = false,
bool includeFlexibleSpace = false
}) {
return MaterialApp(
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
elevation: 0, elevation: 0,
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) { backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.scrolledUnder) return states.contains(MaterialState.scrolledUnder) ? scrolledColor : defaultColor;
? scrolledColor
: defaultColor;
}), }),
title: const Text('AppBar'), title: const Text('AppBar'),
flexibleSpace: includeFlexibleSpace
? const FlexibleSpaceBar(title: Text('FlexibleSpace'))
: null,
), ),
body: ListView( body: ListView(
reverse: reverse,
children: <Widget>[ children: <Widget>[
Container(height: contentHeight, color: Colors.teal), Container(height: 1200.0, color: Colors.teal),
], ],
), ),
), ),
),
); );
Finder findAppBarMaterial() {
return find.descendant(of: find.byType(AppBar), matching: find.byType(Material));
} }
testWidgets('backgroundColor', (WidgetTester tester) async { Color? getAppBarBackgroundColor() {
await tester.pumpWidget( return tester.widget<Material>(findAppBarMaterial()).color;
_buildAppBar(contentHeight: 1200.0) }
);
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight); expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0)); TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
...@@ -2808,7 +2731,7 @@ void main() { ...@@ -2808,7 +2731,7 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor); expect(getAppBarBackgroundColor(), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight); expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0)); gesture = await tester.startGesture(const Offset(50.0, 300.0));
...@@ -2816,96 +2739,67 @@ void main() { ...@@ -2816,96 +2739,67 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight); expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
}); });
testWidgets('backgroundColor with FlexibleSpace', (WidgetTester tester) async { testWidgets('AppBar.backgroundColor with FlexibleSpace MaterialStateColor scrolledUnder', (WidgetTester tester) async {
await tester.pumpWidget( const Color scrolledColor = Color(0xff00ff00);
_buildAppBar(contentHeight: 1200.0, includeFlexibleSpace: true) const Color defaultColor = Color(0xff0000ff);
);
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, -kToolbarHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0));
await gesture.moveBy(const Offset(0.0, kToolbarHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
});
testWidgets('backgroundColor - reverse', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
_buildAppBar(contentHeight: 1200.0, reverse: true) MaterialApp(
home: Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.scrolledUnder) ? scrolledColor : defaultColor;
}),
title: const Text('AppBar'),
flexibleSpace: const FlexibleSpaceBar(
title: Text('FlexibleSpace'),
),
),
body: ListView(
children: <Widget>[
Container(height: 1200.0, color: Colors.teal),
],
),
),
),
); );
await tester.pump();
// In this test case, the content always extends under the AppBar, so it
// should always be the scrolledColor.
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, kToolbarHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0));
await gesture.moveBy(const Offset(0.0, -kToolbarHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor); Finder findAppBarMaterial() {
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight); // There are 2 Material widgets below AppBar. The second is only added if
}); // flexibleSpace is non-null.
return find.descendant(of: find.byType(AppBar), matching: find.byType(Material)).first;
}
testWidgets('backgroundColor with FlexibleSpace - reverse', (WidgetTester tester) async { Color? getAppBarBackgroundColor() {
await tester.pumpWidget( return tester.widget<Material>(findAppBarMaterial()).color;
_buildAppBar( }
contentHeight: 1200.0,
reverse: true,
includeFlexibleSpace: true,
)
);
await tester.pump();
// In this test case, the content always extends under the AppBar, so it expect(getAppBarBackgroundColor(), defaultColor);
// should always be the scrolledColor.
expect(getAppBarBackgroundColor(tester), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight); expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0)); TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, kToolbarHeight)); await gesture.moveBy(const Offset(0.0, -kToolbarHeight));
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor); expect(getAppBarBackgroundColor(), scrolledColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight); expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
gesture = await tester.startGesture(const Offset(50.0, 300.0)); gesture = await tester.startGesture(const Offset(50.0, 300.0));
await gesture.moveBy(const Offset(0.0, -kToolbarHeight)); await gesture.moveBy(const Offset(0.0, kToolbarHeight));
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), scrolledColor); expect(getAppBarBackgroundColor(), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight); expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
}); });
testWidgets('_handleScrollNotification safely calls setState()', (WidgetTester tester) async { testWidgets('AppBar._handleScrollNotification safely calls setState()', (WidgetTester tester) async {
// Regression test for failures found in Google internal issue b/185192049. // Regression test for failures found in Google internal issue b/185192049.
final ScrollController controller = ScrollController(initialScrollOffset: 400); final ScrollController controller = ScrollController(initialScrollOffset: 400);
await tester.pumpWidget( await tester.pumpWidget(
...@@ -2931,16 +2825,17 @@ void main() { ...@@ -2931,16 +2825,17 @@ void main() {
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); });
testWidgets('does not trigger on horizontal scroll', (WidgetTester tester) async { testWidgets('AppBar scrolledUnder does not trigger on horizontal scroll', (WidgetTester tester) async {
const Color scrolledColor = Color(0xff00ff00);
const Color defaultColor = Color(0xff0000ff);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
elevation: 0, elevation: 0,
backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) { backgroundColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.scrolledUnder) return states.contains(MaterialState.scrolledUnder) ? scrolledColor : defaultColor;
? scrolledColor
: defaultColor;
}), }),
title: const Text('AppBar'), title: const Text('AppBar'),
), ),
...@@ -2954,70 +2849,29 @@ void main() { ...@@ -2954,70 +2849,29 @@ void main() {
), ),
); );
expect(getAppBarBackgroundColor(tester), defaultColor); Finder findAppBarMaterial() {
return find.descendant(of: find.byType(AppBar), matching: find.byType(Material));
}
Color? getAppBarBackgroundColor() {
return tester.widget<Material>(findAppBarMaterial()).color;
}
expect(getAppBarBackgroundColor(), defaultColor);
TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0)); TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(-100.0, 0.0)); await gesture.moveBy(const Offset(-100.0, 0.0));
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
gesture = await tester.startGesture(const Offset(50.0, 400.0)); gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(100.0, 0.0)); await gesture.moveBy(const Offset(100.0, 0.0));
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor); expect(getAppBarBackgroundColor(), defaultColor);
});
testWidgets('backgroundColor - not triggered in reverse for short content', (WidgetTester tester) async {
await tester.pumpWidget(
_buildAppBar(
contentHeight: 200.0,
reverse: true,
)
);
await tester.pump();
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
final TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, kToolbarHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
});
testWidgets('backgroundColor with FlexibleSpace - not triggered in reverse for short content', (WidgetTester tester) async {
await tester.pumpWidget(
_buildAppBar(
contentHeight: 200.0,
reverse: true,
includeFlexibleSpace: true,
)
);
await tester.pump();
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
final TestGesture gesture = await tester.startGesture(const Offset(50.0, 400.0));
await gesture.moveBy(const Offset(0.0, kToolbarHeight));
await gesture.up();
await tester.pumpAndSettle();
expect(getAppBarBackgroundColor(tester), defaultColor);
expect(tester.getSize(findAppBarMaterial()).height, kToolbarHeight);
});
});
}); });
testWidgets('AppBar.preferredHeightFor', (WidgetTester tester) async { testWidgets('AppBar.preferredHeightFor', (WidgetTester tester) async {
......
...@@ -349,7 +349,6 @@ void main() { ...@@ -349,7 +349,6 @@ void main() {
' Material\n' ' Material\n'
' _ScrollNotificationObserverScope\n' ' _ScrollNotificationObserverScope\n'
' NotificationListener<ScrollNotification>\n' ' NotificationListener<ScrollNotification>\n'
' NotificationListener<ScrollMetricsNotification>\n'
' ScrollNotificationObserver\n' ' ScrollNotificationObserver\n'
' _ScaffoldScope\n' ' _ScaffoldScope\n'
' Scaffold-[LabeledGlobalKey<ScaffoldState>#00000]\n' ' Scaffold-[LabeledGlobalKey<ScaffoldState>#00000]\n'
......
...@@ -2339,7 +2339,6 @@ void main() { ...@@ -2339,7 +2339,6 @@ void main() {
' Material\n' ' Material\n'
' _ScrollNotificationObserverScope\n' ' _ScrollNotificationObserverScope\n'
' NotificationListener<ScrollNotification>\n' ' NotificationListener<ScrollNotification>\n'
' NotificationListener<ScrollMetricsNotification>\n'
' ScrollNotificationObserver\n' ' ScrollNotificationObserver\n'
' _ScaffoldScope\n' ' _ScaffoldScope\n'
' Scaffold\n' ' Scaffold\n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment