我正在尝试使用 ScrollablePositionedList 实现 pull to refresh。但得到错误。有没有办法同时实现。
Expanded(child: RefreshIndicator(
onRefresh: _pullToRefresh,
child: ScrollablePositionedList.builder(
physics: const AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
itemScrollController: _scrollController,
padding: EdgeInsets.only(top: 8),
itemCount: listTemp!= null ? listTemp.length : 0,
itemBuilder: (BuildContext context, int index) {
if (index == listTemp.length - 1) {
height = 30;
} else {
height = 50;
}
return Container(
child: GestureDetector(
onTap: (){
print("Index:: $index");
_scrollController.scrollTo(index: index, duration: Duration(seconds: 1));
},
child: ListItem(
height: height,
list: listTemp,
index: index,
image: rImage,
),
),
);
},
),
),
)
错误:
Unhandled Exception: 'package:scrollable_positioned_list/src/scrollable_positioned_list.dart': Failed assertion: line 225 pos 12: '_scrollableListState != null': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2 ItemScrollController.scrollTo (package:scrollable_positioned_list/src/scrollable_positioned_list.dart:225:12)
#3 _MyListPageState.goToCurrentDateIndex (package:flutter_app/pages/my_list_page.dart:306:29)
#4 _MyListPageState._moveToCurrentTask.<anonymous closure> (package:flutter_app/pages/my_list_page.dart:293:19)
#5 _rootRun (dart:async/zone.dart:1346:47)
#6 _CustomZone.run (dart:async/zone.dart:1258:19)
#7 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)