@@ -2563,6 +2563,156 @@ void main() {
2563
2563
expect (getAppBarBackgroundColor (tester), defaultColor);
2564
2564
expect (tester.getSize (findAppBarMaterial ()).height, kToolbarHeight);
2565
2565
});
2566
+
2567
+ testWidgets ('scrolledUnderElevation should be maintained when drawer is opened' , (WidgetTester tester) async {
2568
+ final GlobalKey drawerListKey = GlobalKey ();
2569
+ final GlobalKey bodyListKey = GlobalKey ();
2570
+ await tester.pumpWidget (MaterialApp (
2571
+ home: Scaffold (
2572
+ appBar: AppBar (
2573
+ elevation: 0 ,
2574
+ backgroundColor: MaterialStateColor .resolveWith ((Set <MaterialState > states) {
2575
+ return states.contains (MaterialState .scrolledUnder) ? scrolledColor : defaultColor;
2576
+ }),
2577
+ title: const Text ('AppBar' ),
2578
+ ),
2579
+ drawer: Drawer (
2580
+ child: ListView (
2581
+ key: drawerListKey,
2582
+ children: < Widget > [
2583
+ Container (height: 1200 , color: Colors .red),
2584
+ ],
2585
+ ),
2586
+ ),
2587
+ body: ListView (
2588
+ key: bodyListKey,
2589
+ children: < Widget > [
2590
+ Container (height: 1200 , color: Colors .teal),
2591
+ ],
2592
+ ),
2593
+ ),
2594
+ ));
2595
+
2596
+ // Initial state: AppBar should have the default color.
2597
+ expect (getAppBarBackgroundColor (tester), defaultColor);
2598
+
2599
+ // Scroll the list view.
2600
+ await tester.drag (find.byKey (bodyListKey), const Offset (0 , - 300 ));
2601
+ await tester.pumpAndSettle ();
2602
+
2603
+ // The AppBar should now have the scrolled color.
2604
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2605
+
2606
+ // Open the drawer.
2607
+ await tester.tap (find.byIcon (Icons .menu));
2608
+ await tester.pumpAndSettle ();
2609
+
2610
+ // The AppBar should still have the scrolled color.
2611
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2612
+
2613
+ // Scroll the list inside the drawer.
2614
+ await tester.drag (find.byKey (drawerListKey), const Offset (0 , - 300 ));
2615
+ await tester.pumpAndSettle ();
2616
+
2617
+ // The AppBar should still have the scrolled color.
2618
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2619
+
2620
+ // Scroll list inside the drawer back to the top.
2621
+ await tester.drag (find.byKey (drawerListKey), const Offset (0 , 300 ));
2622
+ await tester.pumpAndSettle ();
2623
+
2624
+ // The AppBar should still have the scrolled color.
2625
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2626
+
2627
+ // Close the drawer using the Scaffold's method.
2628
+ tester.state <ScaffoldState >(find.byType (Scaffold )).closeDrawer ();
2629
+ await tester.pumpAndSettle ();
2630
+
2631
+ // The AppBar should still have the scrolled color.
2632
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2633
+
2634
+ // Scroll the list view back to the top.
2635
+ await tester.drag (find.byKey (bodyListKey), const Offset (0 , 300 ));
2636
+ await tester.pumpAndSettle ();
2637
+
2638
+ // The AppBar should be back to the default color.
2639
+ expect (getAppBarBackgroundColor (tester), defaultColor);
2640
+ });
2641
+
2642
+ testWidgets ('scrolledUnderElevation should be maintained when endDrawer is opened' , (WidgetTester tester) async {
2643
+ final GlobalKey drawerListKey = GlobalKey ();
2644
+ final GlobalKey bodyListKey = GlobalKey ();
2645
+ await tester.pumpWidget (MaterialApp (
2646
+ home: Scaffold (
2647
+ appBar: AppBar (
2648
+ elevation: 0 ,
2649
+ backgroundColor: MaterialStateColor .resolveWith ((Set <MaterialState > states) {
2650
+ return states.contains (MaterialState .scrolledUnder) ? scrolledColor : defaultColor;
2651
+ }),
2652
+ title: const Text ('AppBar' ),
2653
+ ),
2654
+ endDrawer: Drawer (
2655
+ child: ListView (
2656
+ key: drawerListKey,
2657
+ children: < Widget > [
2658
+ Container (height: 1200 , color: Colors .red),
2659
+ ],
2660
+ ),
2661
+ ),
2662
+ body: ListView (
2663
+ key: bodyListKey,
2664
+ children: < Widget > [
2665
+ Container (height: 1200 , color: Colors .teal),
2666
+ ],
2667
+ ),
2668
+ ),
2669
+ ));
2670
+
2671
+ // Initial state: AppBar should have the default color.
2672
+ expect (getAppBarBackgroundColor (tester), defaultColor);
2673
+
2674
+ // Scroll the list view.
2675
+ await tester.drag (find.byKey (bodyListKey), const Offset (0 , - 300 ));
2676
+ await tester.pumpAndSettle ();
2677
+
2678
+ // The AppBar should now have the scrolled color.
2679
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2680
+
2681
+ // Open the drawer.
2682
+ await tester.tap (find.byIcon (Icons .menu));
2683
+ await tester.pumpAndSettle ();
2684
+
2685
+ // The AppBar should still have the scrolled color.
2686
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2687
+
2688
+ // Scroll the list inside the drawer.
2689
+ await tester.drag (find.byKey (drawerListKey), const Offset (0 , - 300 ));
2690
+ await tester.pumpAndSettle ();
2691
+
2692
+ // The AppBar should still have the scrolled color.
2693
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2694
+
2695
+ // Scroll list inside the drawer back to the top.
2696
+ await tester.drag (find.byKey (drawerListKey), const Offset (0 , 300 ));
2697
+ await tester.pumpAndSettle ();
2698
+
2699
+ // The AppBar should still have the scrolled color.
2700
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2701
+
2702
+ // Close the drawer using the Scaffold's method.
2703
+ tester.state <ScaffoldState >(find.byType (Scaffold )).closeEndDrawer ();
2704
+ await tester.pumpAndSettle ();
2705
+
2706
+ // The AppBar should still have the scrolled color.
2707
+ expect (getAppBarBackgroundColor (tester), scrolledColor);
2708
+
2709
+ // Scroll the list view back to the top.
2710
+ await tester.drag (find.byKey (bodyListKey), const Offset (0 , 300 ));
2711
+ await tester.pumpAndSettle ();
2712
+
2713
+ // The AppBar should be back to the default color.
2714
+ expect (getAppBarBackgroundColor (tester), defaultColor);
2715
+ });
2566
2716
});
2567
2717
2568
2718
// Regression test for https://github.com/flutter/flutter/issues/80256
0 commit comments