SliverAppBar
当我滚动浏览时,如何为我的颜色设置动画CustomScrollView
?
Scaffold(
body: CustomScrollView(
controller: _scrollController,
slivers: [
SliverAppBar(...),
buildBody(),
],
),
);
SliverAppBar
当我滚动浏览时,如何为我的颜色设置动画CustomScrollView
?
Scaffold(
body: CustomScrollView(
controller: _scrollController,
slivers: [
SliverAppBar(...),
buildBody(),
],
),
);
试试下面的代码:
ScrollController _scrollController;
Color _appColor = Colors.black;
@override
void initState() {
super.initState();
_scrollController= ScrollController()..addListener(() {
if(_scrollController.position.pixels == 0){
_appColor = Colors.black;
setState(() {});
}
else if(_scrollController.position.pixels == 100){
_appColor = Colors.red;
setState(() {});
}
});
}
Scaffold(
body: CustomScrollView(
controller: _scrollController,
slivers: [
//put _appColor to appbar backgroundColor
SliverAppBar(),
buildBody(),
],
),
);