Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The return type 'ListView?' isn't a 'Widget', as required by the closure's context.dart

I’m trying to make an async method that returns a ListView, so to add it to the body of my Scaffold I used future builder, but got this error.

The return type 'ListView?' isn't a 'Widget', as required by the closure's context.dart

This is my FuturuBuilder code:

FutureBuilder<ListView>(
          future: getWidgets(context, this.residents),
          builder: ((context, snapshot) {
            if (snapshot.hasData) {
              return snapshot.data
            } else {
              return new ListView();
            }
          }),
        )

The "getWidgets" is the method that returns a ListView with the Containers I need, the "return new ListView()" is just a placeholder.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

add a ! to snapshot.data:

FutureBuilder<ListView>(
          future: getWidgets(context, this.residents),
          builder: ((context, snapshot) {
            if (snapshot.hasData) {
              return snapshot.data!; // add !
            } else {
              return new ListView();
            }
          }),
        )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading