How to make this type of layout using grid layout in flutter

前端 未结 2 1446
既然无缘
既然无缘 2021-01-05 21:57

Multiple grid layouts in one screen

相关标签:
2条回答
  • 2021-01-05 22:16

    Just a ListView with GridViews inside, and don't forget the shrinkWrap true for the GridViews

      class MultipleGridView extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          return Scaffold(
            body: ListView(
              children: <Widget>[
                Text("Title 1"),
                GridView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 5,
                    crossAxisSpacing: 5.0,
                    mainAxisSpacing: 5.0,
                  ),
                  itemCount: 10,
                  itemBuilder: (context, index) {
                    return Container(
                      color: Colors.blue,
                      child: Text("index: $index"),
                    );
                  },
                ),
                Text("Title 2"),
                GridView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 5,
                    crossAxisSpacing: 5.0,
                    mainAxisSpacing: 5.0,
                  ),
                  itemCount: 10,
                  itemBuilder: (context, index) {
                    return Container(
                      color: Colors.blue,
                      child: Text("index: $index"),
                    );
                  },
                ),
                Text("Title 3"),
                GridView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 5,
                    crossAxisSpacing: 5.0,
                    mainAxisSpacing: 5.0,
                  ),
                  itemCount: 10,
                  itemBuilder: (context, index) {
                    return Container(
                      color: Colors.blue,
                      child: Text("index: $index"),
                    );
                  },
                ),
                Text("Title 4"),
                GridView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 5,
                    crossAxisSpacing: 5.0,
                    mainAxisSpacing: 5.0,
                  ),
                  itemCount: 10,
                  itemBuilder: (context, index) {
                    return Container(
                      color: Colors.blue,
                      child: Text("index: $index"),
                    );
                  },
                )
              ],
            ),
          );
        }
      }
    
    0 讨论(0)
  • 2021-01-05 22:35

    Since you are reusing some code again and again and takes up some memory. Why don't we generate that lines of codes dynamically? and yeah, i am new in flutter.

    Text("Title 1"), GridView.builder( physics: NeverScrollableScrollPhysics(), shrinkWrap: true, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 5, crossAxisSpacing: 5.0, mainAxisSpacing: 5.0, ), itemCount: 10, itemBuilder: (context, index) { return Container( color: Colors.blue, child: Text("index: $index"), ); }, ),

    0 讨论(0)
提交回复
热议问题