Flutter CustomScrollView支持自定义内部item
的滚动控件,还支持头部带滑动缩放的SliverAppBar
。需要注意如果CustomScrollView的item嵌套了和他滚动方向相同的控件这不能正常滑动,因为CustomScrollView内部只会维护一个Scrollable
而会子控件会优先消费就会出现只有子控件能滚动的问题。如果有这种需求的场景建议使用NestedScrollView,可以自定义Sliver
class CustomScrollViewApp extends StatelessWidget {
const CustomScrollViewApp({
Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => _CustomScrollViewPage();
}
class _CustomScrollViewPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _CustomScrollViewState();
}
class _CustomScrollViewState extends State<_CustomScrollViewPage> {
var controller = ScrollController();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) => MaterialApp(
home: Scaffold(
bottomNavigationBar: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Ele