0

a sample of what i have in mind

var url = 'https://www.googleapis.com/books/v1/volumes?q=egg';

Future<BookResponse> getData() async {
  var response = await http.get(url);
  var responseBody = jsonDecode(response.body);
  // print(responseBody);

  return BookResponse.fromJson(responseBody);
}

-----

 FutureBuilder<BookResponse>(
            future: getData(),
            builder: (BuildContext context, AsyncSnapshot snapshot) {
              if (snapshot.hasError) print(snapshot.error);
              if (snapshot.hasData) {
                return ListView.builder(
                    itemCount: snapshot.data.items.length,
                    itemBuilder: (context, index) {
                      return Card(
                          child: ListTile(
                        title:
                            Text(snapshot.data.items[index].volumeInfo.title),
                      ));
                    });
              } else
                return Center(child: CircularProgressIndicator());
            },
          )

im trying to create a method that will convert json map into a List<widgets> so i can use it to display items.

i can't find a way to display items as rows and columns.

is it possible to have multiple widgets using FutureBuilder? (one row of books and another row to show authors for example)

if so i will avoid converting it to List<widgets>

PHP Pharaoh
  • 39
  • 1
  • 6

1 Answers1

1

Convert JSON data to objects and:

Row(
  children: entities.map((entity) => Text(entity.text)).toList();
),

It creates a list with widgets.

fartem
  • 2,361
  • 2
  • 8
  • 20
  • i have mapped them with objects, im trying to display them as a row and not a list – PHP Pharaoh Jan 24 '21 at 16:45
  • Row( children: snapshot.data.items .map((entity) => Text(entity.text)) .toList(), ) it's still not displaying. do i need to change the entity ? if im calling items individually in a text(snapshot.data.items[0].title), it works just fine – PHP Pharaoh Jan 25 '21 at 11:24
  • It is not displaying or items incorrectly displaying? – fartem Jan 25 '21 at 11:34
  • Can you add screenshot? – fartem Jan 25 '21 at 13:18
  • i have put them in a row like so: `Row( children: [ for (var i = 0; i < snapshot.data.items.length; i++) Text(snapshot.data.items[i].id) ], )` – PHP Pharaoh Jan 25 '21 at 13:19