I have a scrollable list view in a horizontal format that I want to covert into a grid view with the same elements.
Container(
height: MediaQuery.of(context).size.height / 4,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: homeList.length,
itemBuilder: (ctx, i) {
return GestureDetector(
onTap: () {
if (i == 0) {
_interstitialAd.show();
} else if (i == 1) {
} else if (i == 2) {
sendInvite();
}
},
);
},
),
)
Flutter has the equivalent to ListView.builder
for GridView
. You only need to tell it the number of columns/rows(depending in the orientation) you want.
GridView.builder(
itemCount: homeList.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
if (i == 0) {
_interstitialAd.show();
} else if (i == 1) {
} else if (i == 2) {
sendInvite();
});
},
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.