tp7309 / flutter_sticky_and_expandable_list

粘性头部与分组列表Sliver实现 Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.
MIT License
140 stars 29 forks source link

当items 为空或者items.length =0 时有问题, #6

Closed liaoli closed 4 years ago

liaoli commented 4 years ago

The method '_addFromInteger' was called on null. Receiver: null Tried calling: _addFromInteger(1)

The relevant error-causing widget was: ExampleListView file:///Users/mac/Downloads/flutter_sticky_and_expandable_list-master/example/lib/main.dart:43:50 When the exception was thrown, this was the stack:

0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)

1 int.+ (dart:core-patch/integers.dart:12:38)

2 SliverExpandableChildDelegate._buildSectionRealIndexes (package:sticky_and_expandable_list/src/sliver_expandable_list.dart:214:22)

3 new SliverExpandableChildDelegate (package:sticky_and_expandable_list/src/sliver_expandable_list.dart:81:30)

4 _ExampleListViewState.build (package:example/example_listview.dart:18:20)

tp7309 commented 4 years ago

需要确保传入的sectionList中的每个section不为空,section.getItems()为空应该是没问题的。

liaoli commented 4 years ago

section.getItems()为空或者 length =0 的确有问题

realIndex += 1 + section.getItems()?.length ?? 0; 改成 int value = section.getItems()?.length ?? 0; realIndex += 1 + value; 就可以了

tp7309 commented 4 years ago

按说是等价的才对,难道有运算符优先级问题?晚上回去看看。

tp7309 commented 4 years ago

已处理,感谢反馈。