diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 9cdc638d50..53705ebfb1 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -763,8 +763,7 @@ class _AppBarState extends State { } void _handleScrollNotification(ScrollNotification notification) { - if (notification is ScrollUpdateNotification && widget.notificationPredicate(notification) - && Scaffold.isBodyDescendant(notification.context!)) { + if (notification is ScrollUpdateNotification && widget.notificationPredicate(notification)) { final bool oldScrolledUnder = _scrolledUnder; final ScrollMetrics metrics = notification.metrics; switch (metrics.axisDirection) { diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index b483212994..75a377012f 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -1994,17 +1994,6 @@ class Scaffold extends StatefulWidget { } } - /// Whether the given context is descendant of the [Scaffold.body]. - /// - /// This is used by [AppBar] to determine if the [AppBar] should listen to - /// [ScrollNotification] from the [Scrollable]s in the [Scaffold.body]. - /// - /// It returns true if the given context is descendant of the [Scaffold.body]. - static bool isBodyDescendant(BuildContext context) { - final _BodyBuilder? body = context.findAncestorWidgetOfExactType<_BodyBuilder>(); - return body != null; - } - @override ScaffoldState createState() => ScaffoldState(); } diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index bff098e815..8c43d4a0b8 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -4501,75 +4501,4 @@ void main() { expect(buttonWasPressed, isFalse); }); }); - - testWidgets("scrolledUnderElevation only listens to scroll notifications from Scaffold's body", (WidgetTester tester) async { - final GlobalKey scaffoldKey = GlobalKey(); - Widget buildWidget() { - return MaterialApp( - theme: ThemeData(useMaterial3: true), - home: Scaffold( - key: scaffoldKey, - appBar: AppBar(), - drawer: Drawer( - child: ListView.builder( - itemCount: 10, - itemBuilder: (BuildContext context, int index) { - return ListTile( - title: Text('$index'), - ); - } - ), - ), - body: ListView.builder( - itemCount: 10, - itemBuilder: (BuildContext context, int index) { - return ListTile( - title: Text('$index'), - ); - } - ), - ), - ); - } - - await tester.pumpWidget(buildWidget()); - - // The first Material is the AppBar's Material. - Material getMaterial() => tester.widget(find.descendant( - of: find.byType(AppBar), - matching: find.byType(Material), - ).first); - - expect(getMaterial().elevation, 0.0); - - // Scroll down the list view in the body. - await tester.drag(find.byType(ListView), const Offset(0.0, -300.0)); - await tester.pumpAndSettle(); - - // AppBar should be elevated. - expect(getMaterial().elevation, 3.0); - - // Scroll up the list view in the body. - await tester.drag(find.byType(ListView), const Offset(0.0, 300.0)); - await tester.pumpAndSettle(); - - // AppBar should not be elevated. - expect(getMaterial().elevation, 0.0); - - final ScaffoldState state = tester.firstState(find.byType(Scaffold)); - - // Open the drawer. - state.openDrawer(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - - expect(scaffoldKey.currentState!.isDrawerOpen, isTrue); - - // Scroll down the list view in the drawer. - await tester.drag(find.byType(ListView).last, const Offset(0.0, -250.0)); - await tester.pump(); - - // AppBar should still not be elevated. - expect(getMaterial().elevation, 0.0); - }); } diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index c2bac88521..3f040b1f65 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -2698,22 +2698,6 @@ void main() { expect(tester.takeException(), isNull); }); - - testWidgets('Scaffold.isBodyDescendant checks if given context is descendant of the body', (WidgetTester tester) async { - final GlobalKey scaffoldKey = GlobalKey(); - final GlobalKey bodyChildKey = GlobalKey(); - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - key: scaffoldKey, - body: SizedBox(key: bodyChildKey), - ), - ), - ); - - expect(Scaffold.isBodyDescendant(scaffoldKey.currentContext!), false); - expect(Scaffold.isBodyDescendant(bodyChildKey.currentContext!), true); - }); } class _GeometryListener extends StatefulWidget {