Flutter入门 - Sliver

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: [
                  SliverAppBar(
//                    title: Text("差不多"),
                    pinned: true,
                    floating: true,
                    expandedHeight: 178.0,
                    flexibleSpace: FlexibleSpaceBar(
                      title: Text("ingha"),
                    ),
                  ),
                  MySliver()
                ],
              )

你可能感兴趣的:(Flutter入门 - Sliver)