@@ -348,7 +348,7 @@ void main() {
348
348
rect: const Rect .fromLTRB (0.0 , 0.0 , 800.0 , 56.0 ),
349
349
children: < TestSemantics > [
350
350
TestSemantics (
351
- id: 11 ,
351
+ id: 18 ,
352
352
rect: const Rect .fromLTRB (0.0 , 36.0 , 800.0 , 92.0 ),
353
353
label: 'Expanded title' ,
354
354
textDirection: TextDirection .ltr,
@@ -409,8 +409,6 @@ void main() {
409
409
label: 'Item 6' ,
410
410
textDirection: TextDirection .ltr,
411
411
),
412
-
413
-
414
412
],
415
413
),
416
414
],
@@ -786,6 +784,22 @@ void main() {
786
784
await tester.pumpWidget (buildFrame (TargetPlatform .linux, true ));
787
785
expect (getTitleBottomLeft (), const Offset (390.0 , 0.0 ));
788
786
});
787
+
788
+ testWidgets ('FlexibleSpaceBar rebuilds when scrolling.' , (WidgetTester tester) async {
789
+ await tester.pumpWidget (const MaterialApp (
790
+ home: SubCategoryScreenView (),
791
+ ));
792
+
793
+ expect (RebuildTracker .count, 1 );
794
+
795
+ // We drag up to fully collapse the space bar.
796
+ for (int i = 0 ; i < 20 ; i++ ) {
797
+ await tester.drag (find.byKey (SubCategoryScreenView .scrollKey), const Offset (0 , - 50.0 ));
798
+ await tester.pumpAndSettle ();
799
+ }
800
+
801
+ expect (RebuildTracker .count, greaterThan (1 ));
802
+ });
789
803
}
790
804
791
805
class TestDelegate extends SliverPersistentHeaderDelegate {
@@ -810,3 +824,76 @@ class TestDelegate extends SliverPersistentHeaderDelegate {
810
824
@override
811
825
bool shouldRebuild (TestDelegate oldDelegate) => false ;
812
826
}
827
+
828
+ class RebuildTracker extends StatelessWidget {
829
+ const RebuildTracker ({super .key});
830
+
831
+ static int count = 0 ;
832
+
833
+ @override
834
+ Widget build (BuildContext context) {
835
+ count++ ;
836
+ return const SizedBox (width: 100 , height: 100 );
837
+ }
838
+ }
839
+
840
+ class SubCategoryScreenView extends StatefulWidget {
841
+ const SubCategoryScreenView ({
842
+ super .key,
843
+ });
844
+
845
+ static const Key scrollKey = Key ('orange box' );
846
+
847
+ @override
848
+ State <SubCategoryScreenView > createState () => _SubCategoryScreenViewState ();
849
+ }
850
+
851
+ class _SubCategoryScreenViewState extends State <SubCategoryScreenView >
852
+ with TickerProviderStateMixin {
853
+ @override
854
+ Widget build (BuildContext context) {
855
+ return Scaffold (
856
+ appBar: AppBar (
857
+ centerTitle: true ,
858
+ title: const Text ('Test' ),
859
+ ),
860
+ body: CustomScrollView (
861
+ key: SubCategoryScreenView .scrollKey,
862
+ slivers: < Widget > [
863
+ SliverAppBar (
864
+ leading: const SizedBox (),
865
+ expandedHeight: MediaQuery .of (context).size.width / 1.7 ,
866
+ collapsedHeight: 0 ,
867
+ toolbarHeight: 0 ,
868
+ titleSpacing: 0 ,
869
+ leadingWidth: 0 ,
870
+ flexibleSpace: const FlexibleSpaceBar (
871
+ background: AspectRatio (
872
+ aspectRatio: 1.7 ,
873
+ child: RebuildTracker (),
874
+ ),
875
+ ),
876
+ ),
877
+ const SliverToBoxAdapter (child: SizedBox (height: 12 )),
878
+ SliverToBoxAdapter (
879
+ child: GridView .builder (
880
+ gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount (
881
+ crossAxisCount: 3 ,
882
+ ),
883
+ shrinkWrap: true ,
884
+ physics: const NeverScrollableScrollPhysics (),
885
+ itemCount: 300 ,
886
+ itemBuilder: (BuildContext context, int index) {
887
+ return Card (
888
+ color: Colors .amber,
889
+ child: Center (child: Text ('$index ' )),
890
+ );
891
+ },
892
+ ),
893
+ ),
894
+ const SliverToBoxAdapter (child: SizedBox (height: 12 )),
895
+ ],
896
+ ),
897
+ );
898
+ }
899
+ }
0 commit comments