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

Re-land reverse case for AppBar scrolled under (#102343)

parent 3bd19f22
......@@ -767,18 +767,34 @@ class _AppBarState extends State<AppBar> {
}
void _handleScrollNotification(ScrollNotification notification) {
if (notification is ScrollUpdateNotification) {
final bool oldScrolledUnder = _scrolledUnder;
_scrolledUnder = notification.depth == 0
&& notification.metrics.extentBefore > 0
&& notification.metrics.axis == Axis.vertical;
final ScrollMetrics metrics = notification.metrics;
if (notification.depth != 0) {
_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) {
setState(() {
// React to a change in MaterialState.scrolledUnder
});
}
}
}
Color _resolveColor(Set<MaterialState> states, Color? widgetColor, Color? themeColor, Color defaultColor) {
return MaterialStateProperty.resolveAs<Color?>(widgetColor, states)
......
......@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
import 'framework.dart';
import 'notification_listener.dart';
import 'scroll_notification.dart';
import 'scroll_position.dart';
/// A [ScrollNotification] listener for [ScrollNotificationObserver].
///
......@@ -151,7 +152,18 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
@override
Widget build(BuildContext context) {
return NotificationListener<ScrollNotification>(
// A ScrollMetricsNotification allows listeners to be notified for an
// 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) {
_notifyListeners(notification);
return false;
......@@ -160,6 +172,7 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
scrollNotificationObserverState: this,
child: widget.child,
),
),
);
}
......@@ -170,3 +183,10 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
super.dispose();
}
}
class _ConvertedScrollMetricsNotification extends ScrollNotification {
_ConvertedScrollMetricsNotification({
required super.metrics,
required super.context,
});
}
......@@ -349,6 +349,7 @@ void main() {
' Material\n'
' _ScrollNotificationObserverScope\n'
' NotificationListener<ScrollNotification>\n'
' NotificationListener<ScrollMetricsNotification>\n'
' ScrollNotificationObserver\n'
' _ScaffoldScope\n'
' Scaffold-[LabeledGlobalKey<ScaffoldState>#00000]\n'
......
......@@ -2339,6 +2339,7 @@ void main() {
' Material\n'
' _ScrollNotificationObserverScope\n'
' NotificationListener<ScrollNotification>\n'
' NotificationListener<ScrollMetricsNotification>\n'
' ScrollNotificationObserver\n'
' _ScaffoldScope\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