美文网首页
Flutter List Grid

Flutter List Grid

作者: Sunooo | 来源:发表于2023-04-15 14:22 被阅读0次

    直接看代码案例快速入手Flutter

    本文介绍ListView, GridView

    ListView类似与iOS中的UITabelView, GridView类似于iOS中的UICollectionView.

    🎉下载GitHub仓库,直接体验

    ListView

    ListView.builder(
        physics: const BouncingScrollPhysics(),
        itemCount: 50,
        itemBuilder: (BuildContext context, int index) {
        return ListTile(title: Text('Item ${index + 1}'));
        },
    ),
    ListView(
        children: const <Widget>[
        ListTile(title: Text('Item 1')),
        ListTile(title: Text('Item 2')),
        ListTile(title: Text('Item 3')),
        ],
    ),
    ListView(
        scrollDirection: Axis.horizontal,
        children: <Widget>[
        Container(width: 200, color: Colors.red),
        Container(width: 200, color: Colors.blue),
        Container(width: 200, color: Colors.green),
        ],
    )
    

    GridView

    GridView.builder(
        physics: const BouncingScrollPhysics(),
        itemCount: 21,
        gridDelegate:
            const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
        itemBuilder: (BuildContext context, int index) {
            return Stack(
                children: [
                Container(
                color: Colors.primaries[index % Colors.primaries.length]),
                Text('Item ${index + 1}')
                ],
            );
        },
    ),
    GridView(
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2),
        children: <Widget>[
            Container(color: Colors.red),
            Container(color: Colors.blue),
            Container(color: Colors.green),
            Container(color: Colors.yellow),
        ],
    ),
    

    相关文章

      网友评论

          本文标题:Flutter List Grid

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