Search code examples
androidflutterdartflutter-navigation

I Want to send data to one page and display another page in flutter


I am building a flutter app in which on click of a Gridview Cell I want to display a new page and send the id of the grid cell to a different page, other than the display page. How to do that with Navigator


Solution

  • You just pass the content to the next page via its constructor. The Gridview Cell has an onClick handler I think, if not you can wrap it using a GestureDetector and use the onTap method there and do something like that:

    onClick: () => {
      Navigator.of(context).push(
        MaterialPageRoute(
          builder: (context) => SecondPage(id),
        ),
      );
    }
    

    where id is a variable stored in the GridviewCell. It comes down to how you structure the data in the widget really.