Skip to content

Commit cc0ecbf

Browse files
author
Liu Yanbo
committedJan 31, 2019
[1.0.3 ]fix bug
1 parent 753d2e0 commit cc0ecbf

File tree

7 files changed

+142
-434
lines changed

7 files changed

+142
-434
lines changed
 

‎.idea/libraries/Dart_Packages.xml

+5-285
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/workspace.xml

+101-98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
## [0.2.5] - fix hint
1515
## [1.0.0] - release stable version
1616
## [1.0.1] - add always scroll physics
17-
## [1.0.2] - re-format
17+
## [1.0.2] - re-format
18+
## [1.0.3] - fix bug for empty list

‎example/ios/Runner.xcodeproj/project.pbxproj

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
11-
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
1211
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1312
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1413
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -41,7 +40,6 @@
4140
/* Begin PBXFileReference section */
4241
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4342
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
44-
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
4543
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4644
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4745
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@@ -74,7 +72,6 @@
7472
9740EEB11CF90186004384FC /* Flutter */ = {
7573
isa = PBXGroup;
7674
children = (
77-
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
7875
3B80C3931E831B6300D905FE /* App.framework */,
7976
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
8077
9740EEBA1CF902C7004384FC /* Flutter.framework */,
@@ -192,7 +189,6 @@
192189
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
193190
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
194191
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
195-
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
196192
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
197193
);
198194
runOnlyForDeploymentPostprocessing = 0;

‎example/lib/FullList.dart

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ class _FullListState extends State<FullList> {
2020
super.dispose();
2121
}
2222

23-
int sectionCount = 4;
24-
final controller = SectionTableController(
25-
sectionTableViewScrollTo: (section, row, isScrollDown) {
23+
int sectionCount = 0;
24+
final controller = SectionTableController(sectionTableViewScrollTo: (section, row, isScrollDown) {
2625
print('received scroll to $section $row scrollDown:$isScrollDown');
2726
});
2827
final refreshController = RefreshController();
@@ -92,7 +91,7 @@ class _FullListState extends State<FullList> {
9291
refreshController: refreshController,
9392
sectionCount: sectionCount,
9493
numOfRowInSection: (section) {
95-
return section == 0 ? 3 : 1;
94+
return section == 0 ? 1 : 4;
9695
},
9796
cellAtIndexPath: (section, row) {
9897
return Container(

‎lib/flutter_section_table_view.dart

+30-41
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ typedef Widget SectionHeaderCallBack(int section);
1313
typedef double SectionHeaderHeightCallBack(int section);
1414
typedef double DividerHeightCallBack();
1515
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);
1817

1918
class IndexPath {
2019
final int section;
@@ -73,10 +72,8 @@ class SectionTableView extends StatefulWidget {
7372

7473
//tell me cell & header & divider height, so that I can scroll to specific index path
7574
//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
8077
final CellHeightAtIndexPathCallBack
8178
cellHeightAtIndexPath; // must set when use SectionTableController
8279
final SectionTableController
@@ -87,8 +84,7 @@ class SectionTableView extends StatefulWidget {
8784
refreshHeaderBuilder; // custom your own refreshHeader, height = 60.0 is better, other value will result in wrong scroll to indexpath offset
8885
final IndicatorBuilder
8986
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
9288
final bool enablePullUp;
9389
final bool enablePullDown;
9490
final OnRefresh onRefresh;
@@ -130,13 +126,10 @@ class SectionTableView extends StatefulWidget {
130126
failedText: 'Load failed',
131127
idleText: 'Pull up to load more',
132128
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),
135130
);
136131
}),
137-
assert((enablePullDown || enablePullUp)
138-
? refreshController != null
139-
: true),
132+
assert((enablePullDown || enablePullUp) ? refreshController != null : true),
140133
_scrollController = (enablePullDown || enablePullUp)
141134
? refreshController.scrollController
142135
: ScrollController(),
@@ -163,8 +156,8 @@ class _SectionTableViewState extends State<SectionTableView> {
163156
if (offset == null) {
164157
return null;
165158
}
166-
final contentHeight = indexPathToOffsetSearch[
167-
IndexPath(section: widget.sectionCount, row: -1).toString()];
159+
final contentHeight =
160+
indexPathToOffsetSearch[IndexPath(section: widget.sectionCount, row: -1).toString()];
168161

169162
if (listViewKey.currentContext != null && contentHeight != null) {
170163
double listViewHeight = listViewKey.currentContext.size.height;
@@ -228,19 +221,17 @@ class _SectionTableViewState extends State<SectionTableView> {
228221
double dividerHeight = showDivider ? widget.dividerHeight() : 0.0;
229222
for (int i = 0; i < widget.sectionCount; i++) {
230223
if (showSectionHeader) {
231-
indexPathToOffsetSearch[IndexPath(section: i, row: -1).toString()] =
232-
offset;
224+
indexPathToOffsetSearch[IndexPath(section: i, row: -1).toString()] = offset;
233225
offset += widget.sectionHeaderHeight(i);
234226
}
235227
int rows = widget.numOfRowInSection(i);
236228
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;
239230
offset += widget.cellHeightAtIndexPath(i, j) + dividerHeight;
240231
}
241232
}
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
244235
}
245236

246237
//calculate initial scroll offset
@@ -250,9 +241,7 @@ class _SectionTableViewState extends State<SectionTableView> {
250241
// }
251242

252243
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) {
256245
final indexPath = indexToIndexPathSearch[i];
257246
if (indexPath.section >= 0) {
258247
return i;
@@ -261,6 +250,10 @@ class _SectionTableViewState extends State<SectionTableView> {
261250
return index;
262251
}
263252

253+
if (indexToIndexPathSearch.length == 0) {
254+
return;
255+
}
256+
264257
if (indexPathToOffsetSearch != null) {
265258
currentIndex = 0;
266259
for (int i = 0; i < indexToIndexPathSearch.length; i++) {
@@ -269,10 +262,9 @@ class _SectionTableViewState extends State<SectionTableView> {
269262
}
270263
}
271264

272-
// final preIndexPath = findValidIndexPathByIndex(currentIndex, -1);;
265+
// final preIndexPath = findValidIndexPathByIndex(currentIndex, -1);
273266
final currentIndexPath = indexToIndexPathSearch[currentIndex];
274-
final nextIndexPath =
275-
indexToIndexPathSearch[findValidIndexPathByIndex(currentIndex, 1)];
267+
final nextIndexPath = indexToIndexPathSearch[findValidIndexPathByIndex(currentIndex, 1)];
276268
preIndexOffset = indexPathToOffsetSearch[currentIndexPath.toString()];
277269
nextIndexOffset = indexPathToOffsetSearch[nextIndexPath.toString()];
278270
}
@@ -287,8 +279,8 @@ class _SectionTableViewState extends State<SectionTableView> {
287279
return;
288280
}
289281
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);
292284
} else {
293285
widget.scrollController.jumpTo(offset);
294286
}
@@ -305,29 +297,27 @@ class _SectionTableViewState extends State<SectionTableView> {
305297
final nextIndexPath = indexToIndexPathSearch[currentIndex];
306298
currentIndex = findValidIndexPathByIndex(currentIndex, -1);
307299
final currentIndexPath = indexToIndexPathSearch[currentIndex];
308-
preIndexOffset =
309-
indexPathToOffsetSearch[currentIndexPath.toString()];
300+
preIndexOffset = indexPathToOffsetSearch[currentIndexPath.toString()];
310301
nextIndexOffset = indexPathToOffsetSearch[nextIndexPath.toString()];
311302
// print('go previous index $currentIndexPath');
312303
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);
315306
}
316307
}
317308
} else if (currentOffset >= nextIndexOffset) {
318309
//go next cell
319310
if (currentIndex < indexToIndexPathSearch.length - 2) {
320311
currentIndex = findValidIndexPathByIndex(currentIndex, 1);
321312
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()];
326316
nextIndexOffset = indexPathToOffsetSearch[nextIndexPath.toString()];
327317
// print('go next index $currentIndexPath');
328318
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);
331321
}
332322
}
333323
}
@@ -384,8 +374,7 @@ class _SectionTableViewState extends State<SectionTableView> {
384374
}
385375

386376
bool usePullRefresh() {
387-
return (widget.enablePullUp || widget.enablePullDown) &&
388-
widget.refreshController != null;
377+
return (widget.enablePullUp || widget.enablePullDown) && widget.refreshController != null;
389378
}
390379

391380
@override

‎pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_section_table_view
22
description: A iOS like table view (list view) including section, row, section header and divider, support pull refresh
3-
version: 1.0.2
3+
version: 1.0.3
44
author: Realank <realank@126.com>
55
homepage: https://github.com/Realank/flutter_section_table_view
66
environment:

0 commit comments

Comments
 (0)
Please sign in to comment.