Flutter入门 - Sliver
2019-04-15 本文已影响0人
洋葱cy
Sliver - 切片
SliverGrid
class MySliver extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 16,
mainAxisSpacing: 16
),
delegate: SliverChildBuilderDelegate(_build,childCount: 50),
);
}
Widget _build(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.purple,
child: Text("shu $index"),
);
}
}
sliverPadding - 可设置padding
class MySliver extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return SliverPadding(
padding: EdgeInsets.all(18.0),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 16,
mainAxisSpacing: 16
),
delegate: SliverChildBuilderDelegate(_build,childCount: 50),
),
);
}
Widget _build(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.purple,
child: Text("shu $index"),
);
}
}
SliverList -
SliverAppbar -
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
// title: Text("差不多"),
pinned: true,
floating: true,
expandedHeight: 178.0,
flexibleSpace: FlexibleSpaceBar(
title: Text("ingha"),
),
),
MySliver()
],
)