@@ -13,8 +13,7 @@ typedef Widget SectionHeaderCallBack(int section);
13
13
typedef double SectionHeaderHeightCallBack (int section);
14
14
typedef double DividerHeightCallBack ();
15
15
typedef double CellHeightAtIndexPathCallBack (int section, int row);
16
- typedef void SectionTableViewScrollToCallBack (
17
- int section, int row, bool isScrollDown);
16
+ typedef void SectionTableViewScrollToCallBack (int section, int row, bool isScrollDown);
18
17
19
18
class IndexPath {
20
19
final int section;
@@ -73,10 +72,8 @@ class SectionTableView extends StatefulWidget {
73
72
74
73
//tell me cell & header & divider height, so that I can scroll to specific index path
75
74
//work with SectionTableController
76
- final SectionHeaderHeightCallBack
77
- sectionHeaderHeight; // must set when use SectionTableController
78
- final DividerHeightCallBack
79
- dividerHeight; // must set when use SectionTableController
75
+ final SectionHeaderHeightCallBack sectionHeaderHeight; // must set when use SectionTableController
76
+ final DividerHeightCallBack dividerHeight; // must set when use SectionTableController
80
77
final CellHeightAtIndexPathCallBack
81
78
cellHeightAtIndexPath; // must set when use SectionTableController
82
79
final SectionTableController
@@ -87,8 +84,7 @@ class SectionTableView extends StatefulWidget {
87
84
refreshHeaderBuilder; // custom your own refreshHeader, height = 60.0 is better, other value will result in wrong scroll to indexpath offset
88
85
final IndicatorBuilder
89
86
refreshFooterBuilder; // custom your own refreshFooter, height = 60.0 is better
90
- final Config refreshHeaderConfig,
91
- refreshFooterConfig; // configure your refresh header and footer
87
+ final Config refreshHeaderConfig, refreshFooterConfig; // configure your refresh header and footer
92
88
final bool enablePullUp;
93
89
final bool enablePullDown;
94
90
final OnRefresh onRefresh;
@@ -130,13 +126,10 @@ class SectionTableView extends StatefulWidget {
130
126
failedText: 'Load failed' ,
131
127
idleText: 'Pull up to load more' ,
132
128
idleIcon: const Icon (Icons .arrow_upward, color: Colors .grey),
133
- releaseIcon:
134
- const Icon (Icons .arrow_downward, color: Colors .grey),
129
+ releaseIcon: const Icon (Icons .arrow_downward, color: Colors .grey),
135
130
);
136
131
}),
137
- assert ((enablePullDown || enablePullUp)
138
- ? refreshController != null
139
- : true ),
132
+ assert ((enablePullDown || enablePullUp) ? refreshController != null : true ),
140
133
_scrollController = (enablePullDown || enablePullUp)
141
134
? refreshController.scrollController
142
135
: ScrollController (),
@@ -163,8 +156,8 @@ class _SectionTableViewState extends State<SectionTableView> {
163
156
if (offset == null ) {
164
157
return null ;
165
158
}
166
- final contentHeight = indexPathToOffsetSearch[
167
- IndexPath (section: widget.sectionCount, row: - 1 ).toString ()];
159
+ final contentHeight =
160
+ indexPathToOffsetSearch[ IndexPath (section: widget.sectionCount, row: - 1 ).toString ()];
168
161
169
162
if (listViewKey.currentContext != null && contentHeight != null ) {
170
163
double listViewHeight = listViewKey.currentContext.size.height;
@@ -228,19 +221,17 @@ class _SectionTableViewState extends State<SectionTableView> {
228
221
double dividerHeight = showDivider ? widget.dividerHeight () : 0.0 ;
229
222
for (int i = 0 ; i < widget.sectionCount; i++ ) {
230
223
if (showSectionHeader) {
231
- indexPathToOffsetSearch[IndexPath (section: i, row: - 1 ).toString ()] =
232
- offset;
224
+ indexPathToOffsetSearch[IndexPath (section: i, row: - 1 ).toString ()] = offset;
233
225
offset += widget.sectionHeaderHeight (i);
234
226
}
235
227
int rows = widget.numOfRowInSection (i);
236
228
for (int j = 0 ; j < rows; j++ ) {
237
- indexPathToOffsetSearch[IndexPath (section: i, row: j).toString ()] =
238
- offset;
229
+ indexPathToOffsetSearch[IndexPath (section: i, row: j).toString ()] = offset;
239
230
offset += widget.cellHeightAtIndexPath (i, j) + dividerHeight;
240
231
}
241
232
}
242
- indexPathToOffsetSearch[IndexPath (section: widget.sectionCount, row: - 1 )
243
- . toString ()] = offset; //list view length
233
+ indexPathToOffsetSearch[IndexPath (section: widget.sectionCount, row: - 1 ). toString ()] =
234
+ offset; //list view length
244
235
}
245
236
246
237
//calculate initial scroll offset
@@ -250,9 +241,7 @@ class _SectionTableViewState extends State<SectionTableView> {
250
241
// }
251
242
252
243
int findValidIndexPathByIndex (int index, int pace) {
253
- for (int i = index + pace;
254
- (i >= 0 && i < indexToIndexPathSearch.length);
255
- i += pace) {
244
+ for (int i = index + pace; (i >= 0 && i < indexToIndexPathSearch.length); i += pace) {
256
245
final indexPath = indexToIndexPathSearch[i];
257
246
if (indexPath.section >= 0 ) {
258
247
return i;
@@ -261,6 +250,10 @@ class _SectionTableViewState extends State<SectionTableView> {
261
250
return index;
262
251
}
263
252
253
+ if (indexToIndexPathSearch.length == 0 ) {
254
+ return ;
255
+ }
256
+
264
257
if (indexPathToOffsetSearch != null ) {
265
258
currentIndex = 0 ;
266
259
for (int i = 0 ; i < indexToIndexPathSearch.length; i++ ) {
@@ -269,10 +262,9 @@ class _SectionTableViewState extends State<SectionTableView> {
269
262
}
270
263
}
271
264
272
- // final preIndexPath = findValidIndexPathByIndex(currentIndex, -1);;
265
+ // final preIndexPath = findValidIndexPathByIndex(currentIndex, -1);
273
266
final currentIndexPath = indexToIndexPathSearch[currentIndex];
274
- final nextIndexPath =
275
- indexToIndexPathSearch[findValidIndexPathByIndex (currentIndex, 1 )];
267
+ final nextIndexPath = indexToIndexPathSearch[findValidIndexPathByIndex (currentIndex, 1 )];
276
268
preIndexOffset = indexPathToOffsetSearch[currentIndexPath.toString ()];
277
269
nextIndexOffset = indexPathToOffsetSearch[nextIndexPath.toString ()];
278
270
}
@@ -287,8 +279,8 @@ class _SectionTableViewState extends State<SectionTableView> {
287
279
return ;
288
280
}
289
281
if (sectionController.animate) {
290
- widget.scrollController. animateTo (offset,
291
- duration: Duration (milliseconds: 250 ), curve: Curves .decelerate);
282
+ widget.scrollController
283
+ . animateTo (offset, duration: Duration (milliseconds: 250 ), curve: Curves .decelerate);
292
284
} else {
293
285
widget.scrollController.jumpTo (offset);
294
286
}
@@ -305,29 +297,27 @@ class _SectionTableViewState extends State<SectionTableView> {
305
297
final nextIndexPath = indexToIndexPathSearch[currentIndex];
306
298
currentIndex = findValidIndexPathByIndex (currentIndex, - 1 );
307
299
final currentIndexPath = indexToIndexPathSearch[currentIndex];
308
- preIndexOffset =
309
- indexPathToOffsetSearch[currentIndexPath.toString ()];
300
+ preIndexOffset = indexPathToOffsetSearch[currentIndexPath.toString ()];
310
301
nextIndexOffset = indexPathToOffsetSearch[nextIndexPath.toString ()];
311
302
// print('go previous index $currentIndexPath');
312
303
if (widget.controller.sectionTableViewScrollTo != null ) {
313
- widget.controller. sectionTableViewScrollTo (
314
- currentIndexPath.section, currentIndexPath.row, false );
304
+ widget.controller
305
+ . sectionTableViewScrollTo ( currentIndexPath.section, currentIndexPath.row, false );
315
306
}
316
307
}
317
308
} else if (currentOffset >= nextIndexOffset) {
318
309
//go next cell
319
310
if (currentIndex < indexToIndexPathSearch.length - 2 ) {
320
311
currentIndex = findValidIndexPathByIndex (currentIndex, 1 );
321
312
final currentIndexPath = indexToIndexPathSearch[currentIndex];
322
- final nextIndexPath = indexToIndexPathSearch[
323
- findValidIndexPathByIndex (currentIndex, 1 )];
324
- preIndexOffset =
325
- indexPathToOffsetSearch[currentIndexPath.toString ()];
313
+ final nextIndexPath =
314
+ indexToIndexPathSearch[findValidIndexPathByIndex (currentIndex, 1 )];
315
+ preIndexOffset = indexPathToOffsetSearch[currentIndexPath.toString ()];
326
316
nextIndexOffset = indexPathToOffsetSearch[nextIndexPath.toString ()];
327
317
// print('go next index $currentIndexPath');
328
318
if (widget.controller.sectionTableViewScrollTo != null ) {
329
- widget.controller. sectionTableViewScrollTo (
330
- currentIndexPath.section, currentIndexPath.row, true );
319
+ widget.controller
320
+ . sectionTableViewScrollTo ( currentIndexPath.section, currentIndexPath.row, true );
331
321
}
332
322
}
333
323
}
@@ -384,8 +374,7 @@ class _SectionTableViewState extends State<SectionTableView> {
384
374
}
385
375
386
376
bool usePullRefresh () {
387
- return (widget.enablePullUp || widget.enablePullDown) &&
388
- widget.refreshController != null ;
377
+ return (widget.enablePullUp || widget.enablePullDown) && widget.refreshController != null ;
389
378
}
390
379
391
380
@override
0 commit comments