Adjust GridView child height according to the dynamic content in flutter

前端 未结 5 2213
执念已碎
执念已碎 2020-12-23 17:14

How to implement this complex view in the flutter?

I am trying to implement a GridView with n columns and the child should be of a certa

5条回答
  •  爱一瞬间的悲伤
    2020-12-23 17:30

    There are two things here:

    1. There is an existing package for doing such layout

    2. In order to make the images look good use BoxFit.cover on the DecorationImage widget.

    There are tons of example in the package repo here

    I just used on of the examples and modified it to include pictures:

    class GridViewExample extends StatefulWidget {
      @override
      _GridViewExampleState createState() => new _GridViewExampleState();
    }
    
    class _GridViewExampleState extends State {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          body: new Padding(
            padding: const EdgeInsets.all(8.0),
            child: new StaggeredGridView.countBuilder(
      crossAxisCount: 4,
      itemCount: 8,
      itemBuilder: (BuildContext context, int index) => new Container(
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new NetworkImage("https://i.imgur.com/EVTkpZL.jpg"),
                fit: BoxFit.cover
              )
            )
    
            ),
    
      staggeredTileBuilder: (int index) =>
          new StaggeredTile.count(2, index.isEven ? 2 : 1),
      mainAxisSpacing: 4.0,
      crossAxisSpacing: 4.0,
    ),),
    
        );
      }
    }
    

提交回复
热议问题