Created with <3 with dartpad.dev.
Last active
November 17, 2023 13:59
-
-
Save sorgfal/f349472ba7804a02dfb18ad3fb1fa548 to your computer and use it in GitHub Desktop.
amber-aqueduct-1548
This file contains hidden or 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
| import 'package:http/http.dart' as http; | |
| import 'dart:convert'; | |
| void main() async { | |
| final todo = await getTodoById(id: 1).then((data) { | |
| /// Парсинг в дто | |
| return data; | |
| }).onError((e, s) => null); | |
| print(todo); | |
| } | |
| Future< | |
| ({ | |
| int userId, | |
| int id, | |
| String title, | |
| bool completed, | |
| })?> getTodoById({required int id}) async { | |
| final responseData = await http | |
| .get(Uri.parse('https://jsonplaceholder.typicode.com/todos/$id')) | |
| .then((resp) { | |
| return jsonDecode(resp.body); | |
| }); | |
| return ( | |
| userId: responseData['userId'] as int, | |
| id: responseData['id'] as int, | |
| title: responseData['title'] as String, | |
| completed: responseData['completed'] as bool, | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment