Last active
July 10, 2020 14:20
-
-
Save stephaniefash/930cbd871e7c6636b39ee841f4240916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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