fluttergridviewwhitespace

Problem with size of items in GridView in Flutter


The problem that occurs in GridView is that there is a space between the items that are created in the second row and later, as in the image below. GridView

Item Widget:

return Material(
      color: MyColors.Transparent,
      child: Container(
        margin: EdgeInsets.only(left: 3.5, right: 3.5),
        width: 120,
        child: 
            Card(
                color: MyColors.Shadow,
                child: InkWell(
                    onTap: () {
                      AppController.Debug(Index);
                    },
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Image.network(
                            height: 50,
                            width: Variables.MATCH_PARENT,
                            "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4xhc0rw70Yodsy2N2FKbxKJxCE8dAIG0sBA&s"),
                        SizedBox(
                          height: 7,
                        ),
                        Container(
                            margin: EdgeInsets.symmetric(horizontal: 5),
                            child: Align(
                              alignment: Alignment.centerRight,
                              child: CustomWidget(
                                ' Item $Index',
                                FontSize: 12,
                              ),
                            )),
                      ,
                    )),
          ],
        )
        
        
      ),
    );

GridView:

Directionality(
            textDirection: TextDirection.rtl,
            child: GridView.count(
                crossAxisCount: 4,
                children: items)),

Solution

  • Try This

    Directionality( textDirection: TextDirection.rtl, child: GridView.count( crossAxisCount: 4, mainAxisSpacing: 0,
    crossAxisSpacing: 0,
    childAspectRatio: 1,
    children: items, ), );