Home > Net >  The return type 'ListView' isn't a 'void', as required by the closure'
The return type 'ListView' isn't a 'void', as required by the closure'

Time:01-05

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

CodePudding user response:

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(             //            
  • Related