passing data to a new scree nusing builder (flutter)

Viewed 26

I'm tryng to pass data from grid view builder to a materialpageroute component to a new screen, I already pass movies index, but can't seem to give it to the new screen

grid builder

new page handler

1 Answers

In the first screenshot, you are trying to assign title as a parameter in onTap function. You cannot do that in onTap.

I think you want to pass the title to DetailPage, you can get the title in movies[index], so you don't have to declare a title.

In the second screenshot, if you want to show the title of your movie in the AppBar, you must do it using title parameter.

AppBar(
  title: Text(movies[index].original_title),
),

And you cannot give just one widget to Column's children parameter. It must be a list.

Column(
  children: [
    _yourWidget(),
  ],
), // put your widget inside list

If you have one widget, you don't need to use Column.

Lastly, you get just one movie, so that you don't have to use ListView. You can use a single widget like Container. And if you want your view can be scrollable, you can wrap the Column with SingleChildScrollView, like this:

SingleChildScrollView(
  child: Column(
    children: [
      _yourWidget(),
    ],
  ),
),

Edit: You didn't declare movies at the top:

class DetailPage extends StatelessWidget {
  final Movie? movies; // declare this first
  const DetailPage {...} // your constructor
}
Related