diff --git a/lib/main.dart b/lib/main.dart index d1a852dc81e6bbb642a7719dad1e9bf814f5566c..7e3dd643844879ac56b26fb9d8bd0097336b5bd0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,18 +1,19 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:html'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; Future<List<Album>> fetchAlbum() async { - final List<Album> jsonResponse = []; final response = await http .get(Uri.parse('https://jsonplaceholder.typicode.com/albums/')); if (response.statusCode == 200) { // If the server did return a 200 OK response, // 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 { // If the server did not return a 200 OK response, // then throw an exception. @@ -78,11 +79,16 @@ class _MyAppState extends State<MyApp> { padding: const EdgeInsets.all(16.0), itemCount: snapshot.data!.length, itemBuilder: (BuildContext context, int index){ - return ListTile( - title: Text( - snapshot.data![index].title, + return Card( + child: ListTile( + leading: CircleAvatar( + backgroundColor: Colors.blue, + child: Text(snapshot.data![index].title[0]) ), - ); + title: Center(child: Text( + snapshot.data![index].title)), + ) + ); }, ); }