How to solve the grid view problem in flutter? - flutter

I have a problem of grid view. I add lists as described in 1st screenshot, then the same list will be updated on the another page (as per second screen shot). However, as you can see overflow error, that is happening and I can not solve that. So, can you guys explain how to increase it's height as I add element in the lists. Hope, it is clear.

use childAspectRatio like example below :
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 0.4,
),

Thank you for your reply, but as you told, I applied that, but that is going to be fix height, however, I want this height increase as we increase number of list. (you can see screenshot below)
Consumer<HomeProvider>(
builder: (context, provider, child) => GridView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: provider.allData.length,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: provider.isPress ? 2 : 1,
childAspectRatio: 0.4
),
itemBuilder: ((context, index) {
return provider.allData[index];
}))`enter code here`
enter image description here

Related

Flutter how to remove extra spacing from GridView.builder element?

I have a GridView.builder that build me a grid with elements inside, how can I remove the distance from the bottom of my grid element so that there is no overflow on all devices, I use the screenutil package.
Here is my griddelegate code:
Widget buildProduct(List<Product> product) => GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 20.w / 33.h,
crossAxisSpacing: 10.w,
mainAxisSpacing: 10.h,
),
itemCount: product.length,
itemBuilder: (context, index) {...}
);
need more code to solve the problem but maybe you can try to wrap the Gridview with Expanded and remove shrinkWrap

Flutter Row() - Align 3 widgets evenly in any amount of Columns

I need to show whole my options(Cyties) since Firebase DB in my app so I would like create somethig similar to the screenshot I posted and not quite sure how to. The only way I know to do it is with ListTile and is not the idea.app Colombia from Play Store
I just tried with a ListTile. And Im sure I need an StreamBuilder since the begining.
This is what I did
You just need to use GridView rather then Listview like below
GridView.builder(
itemCount: item.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 4.0, //Adjust spacing as per yours
mainAxisSpacing: 4.0
),
itemBuilder: (BuildContext context, int index){
return //Your Widget in which you want to display for //example Container();
},
)),

How to reduce Gridview.builder default height

I have used GridView.builder to show API data with below code.
GridView.builder(
shrinkWrap: true,
physics: ScrollPhysics(),
itemCount: snapshot.data!.items.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1 / .3,
),
itemBuilder: (context, index) {
return InkWell(
onTap: () {},
child: CategoryItem(categoryItem: snapshot.data!.items[index],
),
);
},
),
Here Now my data length is 4 only. when it increases then data will be scrollable. And that working fine But thing is, I want to get resizable height with data length. It takes a default height which is not compatible.
Is there any way to reduce default height or customize it?
Thanks in advance.
Getting below output :

Why gridview reload images in Flutter?

I'm trying to use show images using by Image.file(File(path)) in gridview. When I scrolling it down and then up it's reloading images. This caused showing them in white. When I'm looking for this issue there is mentions "lazy loading list" but I don't think it's related with this. Also I tried caching Image widget with LruCache but it's still same. How can I prevent this reloading?
Here is my code snippet:
child: GridView.builder(
itemCount: paths.length,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 0.5,
crossAxisSpacing: 6,
mainAxisSpacing: 6,
crossAxisCount: 5,
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () => {remove(paths[index])},
child: Image.file(File(paths[index])),
);
},
),
This is an error: stop reason = EXC_RESOURCE RESOURCE_TYPE_MEMORY flutter
GridView(gridDelegate: gridDelegate, cacheExtent: 9999,)

is their any way we can provide specific height (aspect ratio provides error)to grid item in flutter using GridView.builder

Since i am new to flutter, In the case of gridview.builder, By providing "childAspectRatio: 1/1", the height differs, some devices i am getting overflow by 10pixels etc, is their any way we can provide specific height to grid item.
GridView.builder(
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 0.0,
childAspectRatio: 1 / 1),
itemBuilder: (BuildContext context, int index) {
Map<String, String> product = products[index].cast<String, String>();
return _buildGridItems(index, product);
},
itemCount: products.length,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
)
Only workaround for this problem that i have found is to use expanded widget and use the flex property to size the widgets (if you have column as the child).