Skip to content
Snippets Groups Projects
Commit 765769b5 authored by Christopher Luzzi's avatar Christopher Luzzi
Browse files

Aufgabe 2 fertig

parent f14699b2
No related branches found
No related tags found
No related merge requests found
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:html';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
Future<List<Album>> fetchAlbum() async { Future<List<Album>> fetchAlbum() async {
final List<Album> jsonResponse = [];
final response = await http final response = await http
.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/')); .get(Uri.parse('https://jsonplaceholder.typicode.com/albums/'));
if (response.statusCode == 200) { if (response.statusCode == 200) {
// If the server did return a 200 OK response, // If the server did return a 200 OK response,
// then parse the JSON. // then parse the JSON.
return jsonResponse.map((data) => Album.fromJson(jsonDecode(response.body))).toList(); var jsonResponse = jsonDecode(response.body) as List;
return jsonResponse.map((data) => Album.fromJson(data)).toList();
} else { } else {
// If the server did not return a 200 OK response, // If the server did not return a 200 OK response,
// then throw an exception. // then throw an exception.
...@@ -78,11 +79,16 @@ class _MyAppState extends State<MyApp> { ...@@ -78,11 +79,16 @@ class _MyAppState extends State<MyApp> {
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
itemCount: snapshot.data!.length, itemCount: snapshot.data!.length,
itemBuilder: (BuildContext context, int index){ itemBuilder: (BuildContext context, int index){
return ListTile( return Card(
title: Text( child: ListTile(
snapshot.data![index].title, leading: CircleAvatar(
backgroundColor: Colors.blue,
child: Text(snapshot.data![index].title[0])
), ),
); title: Center(child: Text(
snapshot.data![index].title)),
)
);
}, },
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment