user19660174
user19660174

Reputation:

I have this error while I am using http request?

Hello I have this error after itemBuilder:(){ } Here is the error

The body might complete normally, causing 'null' to be returned, but the return type, 'Widget', is a potentially non-nullable type

Here is my code:

Container(
              child: FutureBuilder(
                future: HttpService().getBs(),
                builder: (BuildContext context,
                    AsyncSnapshot<List<Battles>> snapshot) {
                  if (snapshot.hasData) {
                    List<Bs> s = snapshot.data!;
                    return ListView.separated(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      itemBuilder: (context, index) {
                        s.map((Bs b) {
                          {
                            return Container();
                          }
                        });
                      },
                      separatorBuilder: (context, index) =>
                          SizedBox(height: 10),
                      itemCount: s.length,
                    );
                  } else {
                    return Center(
                        child: CircularProgressIndicator(
                      color: Colors.blue,
                    ));
                  }
                },
              ),

Upvotes: 0

Views: 50

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63779

You have forgot to add return

return  battles.map((Battles battle) {...

You dont have to use map here.

if (snapshot.hasData) {
  List<Battles> battles = snapshot.data!;
  return ListView.separated(
    shrinkWrap: true,
    separatorBuilder: (context, index) => SizedBox(height: 10),
    itemCount: battles.length,
    physics: NeverScrollableScrollPhysics(),
    itemBuilder: (context, index) {
      final battle = battles[index];
      return Container(
        width: 375,
        height: 375,
        child: ... // use this `battle` 
      );
    },
  );
} else {

enter image description here

More about ListView

Upvotes: 1

Related Questions