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

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();
},
)),

Related

How to solve the grid view problem in 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

I am working on my app since a few days now and staggered gridview widget refused to work

For a while now i've been working on an app that needs me to make use of staggered gridview library but the library doesnt seem to be working
StaggeredGridView.countBuilder(
shrinkWrap: true,
physics: const ScrollPhysics(),
crossAxisSpacing: 16,
itemCount: bookList.length,
mainAxisSpacing: 16,
crossAxisCount: 4,
itemBuilder: (_, index) =>BookItem(bookList[index])
staggeredTileBuilder: (_) const StaggeredTile.fit(2)),
These are the error messages i get even after running flutter clear and flutter pub get
Have you updated the plugin perhaps? The StaggeredGridView has been removed/refactored since 0.6.1 I think...
There are other options now. Have a look at the documentation for what would be the best fit for you now.
I believe the error is in this line try changing the underscore to context and add a comma at the end
itemBuilder: (context, index) =>BookItem(bookList[index]),

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.

I need to make a non-scrollable Gridview with itemBuilder

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

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