I need to make a non-scrollable Gridview with itemBuilder - flutter

I want to create a grid view inside a listview. It is now being nested and not working well. I want to make it GridView because I want itemBuilder to view the list in Map with index.
Like this
return GridView.builder(
shrinkWrap: false,
primary: false,
itemCount: kadakkalproducts.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemBuilder: (BuildContext context, int index) {
return SingleProdc(
product_name: kadakkalproducts[index]['name'],
product_picture: kadakkalproducts[index]['picture'],
product_price: kadakkalproducts[index]['price'],
product_image1: kadakkalproducts[index]['image1'],
product_image2: kadakkalproducts[index]['image2'],
product_des: kadakkalproducts[index]['des'],
product_det: kadakkalproducts[index]['det'],
);
},
);
I have used shrinkwrap and primary to stop nested loop. But it doesn't work.
Please help me out to stop scrolling in GridView

Add this line inside your GridView
physics:NeverScrollableScrollPhysics()
https://api.flutter.dev/flutter/widgets/ScrollPhysics-class.html

Related

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 ListView can Stop at each element in Flutter

My question is very simple but I did not find a result.
In a ListView.builder (with horizontal scroll) for example if there are 5 elements the user can scroll them all at once. I would like that the user can scroll only 1 by 1.
In short I would like the animation of the list to stop at each element.
Example of my list :
Widget _list()
{
return ListView.builder(
physics: const ClampingScrollPhysics(),
scrollDirection: _horizontalDisplay? Axis.horizontal : Axis.vertical,
itemCount: data!.length,
itemBuilder: (context, index)
{
return widgetToDisplay(index);
}
);
}
The ListView.builder can't make it, you need to use carousel_slider package

When to use GridView and ListView in flutter since they do the same thing?

What is the differentiation of ListView and GridView? ListView.builder, ListView.separated, Listview.custom vs GridView.builder, GridView.count, GridView.extent
They are not the same thing.
ListView is for one directional way of showing things e.g. list or image carousel.
GridView on the other hand is ready for 2D display of things, e.g. for photo gallery .
You can take a look at the official docs for the difference. Let's see how they're defined in the documentation:
GirdView. (Video):
A scrollable, 2D array of widgets.
ListView. (Video):
A scrollable list of widgets arranged linearly.
ListView vs GridView
ListView: The children are laid out one-dimensionally (direction can be horizontal or vertical).
GridView: The children are laid out two-dimensionally. Even if you don't use the properties that make it visually 2D (by setting crossAxisCount: 1), it's still considered 2D.
Different ListView Constructors
ListView
ListView(
children: [allItems],
);
ListView.builder
It creates a list of items that are easily generated or otherwise need to be dynamically created.
ListView.builder(
itemBuilder: (context, index) => Text("Item $index"),
itemCount: 10, // not required
);
ListView.separated
Similar to ListView.builder. It takes itemBuilder and separatorBuilder to create items and separators dynamically.
ListView.separated(
itemBuilder: (context, index) => Text("Item $index"),
separatorBuilder: (context, index) => Divider(),
itemCount: 10, // not required
);
If itemCount is not specified, it will create an infinite amount of children as the user scrolls.
ListView.custom
To use a custom SliverChildDelegate. It takes a childrenDelegate, which provides the ability to customize additional aspects of the child model.
ListView.custom(
childrenDelegate: mySliverChildDelegate,
);
Different GridView Constructors
GridView.count
It creates a layout with a fixed number of tiles in the cross axis.
GridView.count(
crossAxisCount: 2, // how many items you want across the grid
children: [allItems],
);
GridView.extent
It creates a layout with tiles that have a maximum cross-axis extent.
GridView.extent(
maxCrossAxisExtent: 90.0, // maximum space each child can occupy
children: [allItems],
);
GridView.builder
To create a grid with a large (or infinite) number of children.
Use a SliverGridDelegateWithFixedCrossAxisCount or a SliverGridDelegateWithMaxCrossAxisExtent for the gridDelegate parameter.
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemCount: 6,
itemBuilder: (BuildContext context, int index) {
return itemWidget;
}
);
GridView.custom
To use a custom SliverChildDelegate.
GridView.custom(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
childrenDelegate: mySliverChildDelegate,
);
Note:
Constructors GridView, GridView.builder, and GridView.custom explicitly require a ‘grid delegate’ to be passed to the named parameter, gridDelegate.
While the other constructors, GridView.count and GridView.extent, create such a class object for you.
References:
Flutter documentation for ListView Class and GridView Class
YouTube videos on ListView and GridView by flutter.
Look at this amazing article for an in-depth look at the GridView widget by Greg Perry.

Cant scroll with ListView.builder()

I was wondering if anyone had an issue where they use a ListView.builder() and then it doesn't want to scroll
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: widget.product.category.length,
itemBuilder: (context, index) {
final item = widget.product.category[index];
return ListTile(title: Text(item));
},
)
I'd suggest you do the following:
Remove shrinkWrap and make sure the value passed to itemCount is large enough to make the widget scroll.
If you place the list view inside a vertically scrolling list, it's not going to scroll... In this case, you should probably be using slivers

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).