How do u navigate to different pages using cards built using GridView.builder(). U could navigate only to a common page right?


i.e Each card displayed should either navigate to a different page or should render data according to the api fetched.


Call a funtion based on index of gidview for example

class Grid4 extends StatelessWidget {
void tapped(int index){
if(index == 1){
  //navigate to one 
  } else {
 // navigate to two 
 Widget build(BuildContext context) {
  return Scaffold(
  appBar: AppBar(),
  body: Container(
    padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10),
    child: GridView.builder(
      itemCount: 25,
      itemBuilder: (context, index) =>
              onTap: () => tapped(index),
              child: Container(decoration: BoxDecoration(
                      color: Colors.white70, shape:,
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 5,
        mainAxisSpacing: 40,
        crossAxisSpacing: 50,


Answered By – Vishal_VE

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *