Reputation: 299
How do I get the value of the List data to be accessed from the class Details Page? The value is already set in the constructor via a page route.
class TicketDetailsPage extends StatefulWidget {
final List data; //<--This is the List
TicketDetailsPage({Key key, this.data}) : super(key: key);
@override
State<StatefulWidget> createState() => new _State();
}
class _State extends State<TicketDetailsPage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Ticket Details",
debugShowCheckedModeBanner: false,
home: DetailsPage(),
);
}
}
class DetailsPage extends StatelessWidget {
//<--Access the list right here-->
}
Upvotes: 0
Views: 147
Reputation: 27137
You have to pass the list to DetailsPage, but before that you have to access TicketDetailsPage data in its state using widget in following way.
widget.data
Now You can pass data and accept data in DetailsPage using constructor as below.
class _State extends State<TicketDetailsPage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Ticket Details",
debugShowCheckedModeBanner: false,
home: DetailsPage(data:widget.data),
);
}
}
class DetailsPage extends StatelessWidget {
final List data; //<--This is the List
DetailsPage({this.data});
}
Upvotes: 1