https://blog.naver.com/getinthere/223060684149
Flutter CustomscrollView와 NestedScrollView
플러터 CustomScrollView(with SliverList) 위젯
Flutter SliverAppBar, SliverToBoxAdapter, SliverFixedExtentList, SliverChildBuilderDelegate
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
title: Text("SliverAppBar1"),
backgroundColor: Colors.red,
pinned: false,
expandedHeight: 250,
flexibleSpace: Opacity(opacity: 0.6, child: Text("appbar1")),
),
SliverPersistentHeader(
delegate: MyHeader(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text("메뉴1"),
Text("메뉴2"),
Text("메뉴3"),
],
),
),
),
),
SliverToBoxAdapter(
child: Container(
height: 200,
color: Colors.yellow,
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
childCount: 30,
(context, index) {
return Container(
height: 50,
color: Colors.lightBlue[100 * (index % 9)],
);
},
),
),
],
),
);
}
}
class MyHeader extends SliverPersistentHeaderDelegate {
final Widget child;
MyHeader({required this.child});
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return child;
}
@override
double get maxExtent => 200;
@override
double get minExtent => 60;
@override
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}