Home > front end >  How to keep margins only on inside item?
How to keep margins only on inside item?

Time:12-27

I have a gridview builder and I have set margins on it, is there way to keep the gap only on the middle item, instead of first and last one? I dont want extra padding on sides.

enter image description here

  Container(
                  color: Colors.white,
                  child: TextField()
                ),
                Expanded(
                  child: GridView.builder(
                    itemCount: 13,
                    itemBuilder: (BuildContext context, index) {
                      return Container(
                        color: Colors.red,
                        margin: EdgeInsets.all(4.0),
                        height: 40.0,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.end,
                          children: [
                            Text("${index}")
                          ],
                        ),
                      );

CodePudding user response:

You can use gridDelegate with mainAxisSpacing and crossAxisSpacing. And no need to use margin. Follow the below code

 GridView.builder(
  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 3, crossAxisSpacing: 4, mainAxisSpacing: 4),
  • Related