Skip to content

Instantly share code, notes, and snippets.

@stephaniefash
Last active July 10, 2020 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephaniefash/930cbd871e7c6636b39ee841f4240916 to your computer and use it in GitHub Desktop.
Save stephaniefash/930cbd871e7c6636b39ee841f4240916 to your computer and use it in GitHub Desktop.
class MessageProvider {
final String _url = "https://jsonplaceholder.typicode.com/comments";
Client client = Client();
Future<List<MessageModel>> fetchPosts() async {
final response = await client.get(_url);
if (response.statusCode == 200) {
final parsed = json.decode(response.body);
return parsed.map<MessageModel>((json) => MessageModel.fromJson(json)).toList();
} else {
throw Exception('Failed to load messages');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment