美文网首页Flutter
Flutter入门 - Sliver

Flutter入门 - Sliver

作者: 洋葱cy | 来源:发表于2019-04-15 17:39 被阅读0次
    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()
                    ],
                  )
    

    相关文章

      网友评论

        本文标题:Flutter入门 - Sliver

        本文链接:https://www.haomeiwen.com/subject/lzqpwqtx.html