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 'void', as required by the closure's context.dartreturn_of_invalid_type_from_closure

BlocBuilder<RateFetchCubit, RateFetchState>(
          builder: (context, state) {
            if (state is RateFetchInitial) {
              return const SpinKitFadingCircle(
                color: Colors.grey,
                size: 50.0,
              );
            } else if (state is MarketListed) {
              state.channel.stream.listen((event) {
                var dataList = Market.fromJson(jsonDecode(event.toString())
                    as Map<String, Iterable<dynamic>>);
                print(event.toString());

                return ListView.builder(
                  itemCount: 5,
                  itemBuilder: (context,index){
                  return  const Text("");
                });              });
              }
            }
            return Container();
          },
        )

I am getting

The return type ‘ListView’ isn’t a ‘void’, as required by the
closure’s context.dartreturn_of_invalid_type_from_closure

error on listview.

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 :

Mistake: Your ListView.builder is inside the state.channel.stream.listen get it out

Now

|_ state.channel.streaam.listen
   |_ return Listview.builder

Change it to

|_ state.channel.streaam.listen
|_ return Listview.builder

Code:

          state.channel.stream.listen((event) {
            var dataList = Market.fromJson(jsonDecode(event.toString())
                as Map<String, Iterable<dynamic>>);
            print(event.toString());
                  // It was here 
          }
             return ListView.builder(             // 👈 It should be here
              itemCount: 5,
              itemBuilder: (context,index){
              return  const Text("");
            });              });
        }
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