Pass API Text Data to other Page Flutter

I'm facing an issue regarding API datas, I want the pass the texts, Image generated by API to another screen screen

Here is the

      String _name(dynamic user){
    return user['name']['title'];

  }
 String _description(dynamic user){
    return user['name']['description'];
  }

I want to pass these texts to the next screen using Provider or MaterialRoute Page, How can I do so in a real example

Thanks

Upvotes: 0

Views: 362

Answers (1)

fartem
fartem

Reputation: 2531

You can do this by 2 ways:

  1. Pass a data to screen as arguments. For example:
class SecondScreen extends StatelessWidget {
  final String title;
  final String description;

  SecondScreen(this.title, this.description);
}

And in routing:

Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => SecondScreen(title, description)),
);
  1. Create a model class in Provider and add data to it before moving to another screen and access this data in the second screen.

A Provider basically allows you to access data belonging to class from any widget. Here is a link to the Provider package. You'll find examples over there.

Upvotes: 2

Related Questions