0

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-->
  }

1 Answer 1

1

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});
  }
Sign up to request clarification or add additional context in comments.

1 Comment

@Abion47 thank you for your suggestion. i generally preferred to answer with explanation, but this time i didn't. However, now added some explanation too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.