Phan Thinh
Phan Thinh

Reputation: 3

How to handle error " The return type 'List<Card>' isn't a 'Widget', as required by the closure's context."

I got an error when I tried to display a list of type Future<List?> (variable rssItems). Error: The return type 'Iterable' isn't a 'Widget', as required by the closure's context.

[error is displayed]

FutureBuilder<List<RSSItem>?>(
                  future: rssItems,
                  builder: (context,snapshot)
                  {
                    return ListView.builder(
                      itemCount: snapshot.data!.length,
                        itemBuilder: (context, index){
                          return snapshot.data!.map((e) => Card()).toList();
                        }
                    );
                  },)

erorr: The return type 'List<Card'>' isn't a 'Widget', as required by the closure's context.

Upvotes: 0

Views: 373

Answers (1)

Delwinn
Delwinn

Reputation: 1019

change return to

return snapshot.data!.map((e)=> Card(...args : e));

here ...args stands for the different parameters of Card() widget

Upvotes: 1

Related Questions