写项目时候遇到SliverAppBar顶部隐藏,有两种写法,
1,
2,
结果两种都可以实现,效果差不多,但是NestedScrollView的body中设置ScrollController(设置了会跟内部Controller冲突)来完成下拉刷新,增量加载,滚动到顶部。
https://github.com/fluttercandies/extended_nested_scroll_view/blob/master/README-ZH.md
这个网址里有多重解决办法,但是我都没用,我最后还是用了两个ScrollController来控制。一个是NestedScrollView的Controller
一个是listview的Controller,多个tabview里面的listview的Controller其实可以提出来成为一个。
_scrollConstruct.scrollController.addListener(() {
var innerPos = _scrollConstruct.scrollController.position.pixels;
var maxOuterPos = _nestedScrollViewController.position.maxScrollExtent;
var currentOutPos = _nestedScrollViewController.position.pixels;
if (innerPos >= 0 && currentOutPos < maxOuterPos) {
_nestedScrollViewController.position.animateTo(innerPos + currentOutPos,
curve: Curves.linear, duration: Duration(microseconds: 100));
} else {
var currenParentPos = innerPos + currentOutPos;
_nestedScrollViewController.position
.animateTo(currenParentPos, curve: Curves.linear, duration: Duration(microseconds: 100));
}
});
_nestedScrollViewController.addListener(() {
var currentOutPos = _nestedScrollViewController.position.pixels;
if (currentOutPos <= 0) {
_scrollConstruct.scrollController.position
.animateTo(0, curve: Curves.linear, duration: Duration(microseconds: 100));
}
});