如何在Flutter中使用GridView小部件编辑项目?

问题描述

,我正在GridView中工作,但是我只需要更改一项或多项而不是全部项的布局,例如(height或width..etc)。 childAspectRatio选项它也会更改所有项目,所以这是我需要更改选择的特定项目的问题,我该怎么做?

代码

class StaggeredGridExample extends StatefulWidget {
  @override
  _StaggeredGridExampleState createState() => _StaggeredGridExampleState();
}

class _StaggeredGridExampleState extends State<StaggeredGridExample> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: GridView.count(
      crossAxisCount: 2,childAspectRatio: 16/9,children: [
        Container(
          color: Colors.green,child: Icon(Icons.translate),),Container(
          color: Colors.blueGrey,child: Icon(Icons.shop),Container(
          color: Colors.deepOrangeAccent,child: Icon(Icons.date_range),Container(
          color: Colors.cyan,child: Icon(Icons.radio),Container(
          color: Colors.brown,child: Icon(Icons.favorite_border),],));
  }
}

谢谢!

解决方法

gridview要求所有项目的大小均相同。如果要自定义并使用不同的大小,则需要使用插件。

URL链接:https://pub.dev/packages/flutter_staggered_grid_view