首页 > 解决方案 > Flutter Bloc 在 listview.builder 中不起作用?

问题描述

为什么在 listview.builder 事件中没有多次调用:这仅触发一次 time 。

  class _UsersQuestionsState extends State<UsersQuestions> {
  @override
  Widget build(BuildContext context) {
  Size size = MediaQuery.of(context).size;

  return BlocBuilder<QuestionWatcherBloc, QuestionWatcherState>(
   builder: (context, state) {
    return state.map(
     
      loadInProgress: (_) => const Center(
        child: Text("Loading"),
      ),
      loadSuccess: (state) {
        return ListView.builder(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemCount: state.questions.size,
            itemBuilder: (
              context,
              index,
            ) {
              // ignore: avoid_unnecessary_containers
             //here i want to read another Bloc event for each index and try to update the state but it's called only one time
              context.read<UsersWatcherBloc>().add(
                  UsersWatcherEvent.watchAllUsers(
                      state.questions[index].userId.getorCrash()));

              return Container(
           
               
                child: Column(
                  
                  children: [
                    Row(children: [
                     
                      Wrap(
                        direction: Axis.vertical,
                        children: [
                          BlocBuilder<UsersWatcherBloc, UsersWatcherState>(
                            builder: (context, state) {
                              return state.map(
                                empty: (_) => SizedBox(),
                                initial: (value) => SizedBox(),
                                loadFailure: (value) => SizedBox(),
                                loadInProgress: (value) => SizedBox(),


   // here i want to use that value but it's not updatin 
      according to index
                                loadSuccess: (value) => Text(                                 value.users.first.name.getorCrash()),
                              );
                            },
                          ),

我必须显示提出问题的用户名及其详细信息,以便我致电另一个集团并传递他们的用户 ID,并希望根据帖子获得他们的更新名称,但截至目前,我为每个问题获得相同的用户详细信息。bcs 事件是不为每个索引调用。

标签: flutterdartbloc

解决方案


推荐阅读