@@ -125,40 +125,61 @@ class ExampleVerticalDouble extends StatelessWidget {
125
125
super .key,
126
126
required this .title,
127
127
// this.reverse = false,
128
- // this.headerDirection = AxisDirection.down ,
129
- }); // : assert(axisDirectionToAxis(headerDirection) == Axis.vertical);
128
+ required this .headerPlacement ,
129
+ });
130
130
131
131
final String title;
132
132
// final bool reverse;
133
- // final AxisDirection headerDirection ;
133
+ final HeaderPlacement headerPlacement ;
134
134
135
135
@override
136
136
Widget build (BuildContext context) {
137
137
const numSections = 4 ;
138
138
const numBottomSections = 2 ;
139
+ const numTopSections = numSections - numBottomSections;
139
140
const numPerSection = 10 ;
141
+
142
+ final headerAtBottom = switch (headerPlacement) {
143
+ HeaderPlacement .scrollingStart => false ,
144
+ HeaderPlacement .scrollingEnd => true ,
145
+ };
146
+
147
+ // Choose the "center" sliver so that the sliver which might need to paint
148
+ // a header overflowing the other header is the sliver that paints last.
149
+ final centerKey = headerAtBottom ?
150
+ const ValueKey ('bottom' ) : const ValueKey ('top' );
151
+
152
+ // This is a side effect of our choice of centerKey.
153
+ final topSliverGrowsUpward = headerAtBottom;
154
+
140
155
return Scaffold (
141
156
appBar: AppBar (title: Text (title)),
142
157
body: CustomScrollView (
143
158
semanticChildCount: numSections,
159
+ center: centerKey,
144
160
slivers: [
145
161
SliverStickyHeaderList (
146
- headerPlacement: HeaderPlacement .scrollingStart,
162
+ key: const ValueKey ('top' ),
163
+ headerPlacement: headerPlacement,
147
164
delegate: SliverChildBuilderDelegate (
148
165
childCount: numSections - numBottomSections,
149
166
(context, i) {
150
- final ii = numSections - 1 - i;
167
+ final ii = numBottomSections
168
+ + (topSliverGrowsUpward ? i : numTopSections - 1 - i);
151
169
return StickyHeaderItem (
152
170
allowOverflow: true ,
153
171
header: WideHeader (i: ii),
154
172
child: Column (
173
+ verticalDirection: headerAtBottom
174
+ ? VerticalDirection .up : VerticalDirection .down,
155
175
children: List .generate (numPerSection + 1 , (j) {
156
176
if (j == 0 ) return WideHeader (i: ii);
157
177
return WideItem (i: ii, j: j- 1 );
158
178
})));
159
179
})),
160
180
SliverStickyHeaderList (
161
- headerPlacement: HeaderPlacement .scrollingStart,
181
+ key: const ValueKey ('bottom' ),
182
+ headerPlacement: headerPlacement,
162
183
delegate: SliverChildBuilderDelegate (
163
184
childCount: numBottomSections,
164
185
(context, i) {
@@ -167,10 +188,12 @@ class ExampleVerticalDouble extends StatelessWidget {
167
188
allowOverflow: true ,
168
189
header: WideHeader (i: ii),
169
190
child: Column (
191
+ verticalDirection: headerAtBottom
192
+ ? VerticalDirection .up : VerticalDirection .down,
170
193
children: List .generate (numPerSection + 1 , (j) {
171
- if (j == 0 ) return WideHeader (i: ii);
172
- return WideItem (i: ii, j: j- 1 );
173
- })));
194
+ if (j == 0 ) return WideHeader (i: ii);
195
+ return WideItem (i: ii, j: j- 1 );
196
+ })));
174
197
})),
175
198
]));
176
199
}
@@ -319,8 +342,15 @@ class MainPage extends StatelessWidget {
319
342
];
320
343
final otherItems = [
321
344
_buildButton (context,
322
- title: 'Double slivers' ,
323
- page: ExampleVerticalDouble (title: 'Double slivers' )),
345
+ title: 'Double slivers, headers at top' ,
346
+ page: ExampleVerticalDouble (
347
+ title: 'Double slivers, headers at top' ,
348
+ headerPlacement: HeaderPlacement .scrollingStart)),
349
+ _buildButton (context,
350
+ title: 'Double slivers, headers at bottom' ,
351
+ page: ExampleVerticalDouble (
352
+ title: 'Double slivers, headers at bottom' ,
353
+ headerPlacement: HeaderPlacement .scrollingEnd)),
324
354
];
325
355
return Scaffold (
326
356
appBar: AppBar (title: const Text ('Sticky Headers example' )),
0 commit comments