Text not visible in trailing of gridtilebar in gridview flutter

Viewed 12

Iam developing an ecommerce app with the items to add and remove button below the product image in gridview. Inbetween the button, i have a text widget to show the number of items for add and remove.The problem is the text widget is not displaying inbetwen.

Padding(
                    padding: const EdgeInsets.only(right: 8, top: 10),
                    child: SizedBox(
                      child: Text(
                        '${item == null ? 0 : item}',
                        style: TextStyle(
                            fontSize: 20,
                            fontWeight: FontWeight.w600,
                            color: Colors.black),
                      ),
                    ),
                  ),

image

1 Answers

by default, gridview children has same size for all children based on aspectratio.

Solution:

opsi 1: Fitted box will scaled down your widget child size.

Gridview.count(
....
children:[
  FittedBox(
    child: // your widget her

opsi 2: set childAspectRatio: to your gridview,

GridView.count(
   //var size = MediaQuery.of(context).size;
   // double itemHeight = (size.height - kToolbarHeight - 24) / 2;
   // double itemWidth = size.width / 2;
   // this value that i usually use in mobile, idk for web size. you can try by your self
   childAspectRatio: itemHeight / itemWidth,
   children: []

this will customize your grid space

Related