Reputation: 454
I am trying to add a new custom Button in gridview.builder. In my gridview, I have 5 items please see the image
please look at my simple code.
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemCount: _categoryList.length,
itemBuilder: (context, index) {
if (_categoryList.length != 0) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(_categoryList[index].icon,),
),
);
} else
return Container();
},
),
Upvotes: 4
Views: 5137
Reputation: 725
At the child you can ask for index == 5 and show a Button-Widget instead of Photo-List-Item:
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemCount: _categoryList.length,
itemBuilder: (context, index) {
if (_categoryList.length != 0) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: index == 5 ? myButton() : CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(_categoryList[index].icon,),
),
);
} else
return Container();
},
),
Upvotes: 3