[Flutter] SliverList (Widget of the Week)

birdgang
3 min readSep 17, 2020

--

# 참조

# 개념

sliver인 SliverList는 일반적인 ListView와 비슷하게 동작한다. delegate 항목에서 SliverChildBuilderDelegate 함수를 통해 아이템을 생성 및 추가할 수 있다.

# 유튜브 영상

# 샘플 코드

class SliverAppBarList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.white,
floating: false,
pinned: true,
expandedHeight: 200.0,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text(
"SliverList Widget",
style: TextStyle(
color: Colors.black87,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
background: Container(
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: Colors.black26,
width: 1.0,
),
),
),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Container(
height: 100.0,
color: Color((math.Random().nextDouble() * 0xFFFFFF).toInt() << 0).withOpacity(1.0),
child: Center(
child: Text(
"Sliver List item: $index",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
),
);
},),
),
],
),

);
}
}

# 결과 화면

--

--