flutter 返回类型“ListView”不是闭包上下文所要求的“void”,dartreturn_of_invalid_type_from_closure

uxhixvfz  于 2023-01-06  发布在  Flutter
关注(0)|答案(1)|浏览(124)
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();
          },
        )

我越来越
返回类型“ListView”不是闭包上下文所要求的“void”。dartreturn_of_invalid_type_from_closure

0ejtzxu1

0ejtzxu11#

错误:您的ListView.builderstate.channel.stream.listen内部,请将其取出
现在

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

改成

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

代码:

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("");
            });              });
        }

相关问题