flutter 更改后BlocBuilder未重新生成UI

dced5bon  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(147)

我有一个绘制捐赠条的BlocBuilder,但是当对捐赠的更改来自套接字时,由于某种原因,它在调用emit后没有重新绘制UI。
阻塞

BlocBuilder<PatientCardBloc, PatientCardState>(
                    bloc: PatientCardBloc(),
                    builder: (context, state) {
                      return DonatedProgress(
                        name: patient.firstName,
                        disease: patient.problem.disease,
                        currentAmount:
                            state.status != PatientCardStatus.initialized
                                ? patient.currentAmount
                                : patient.id == state.patient.id
                                    ? state.patient.currentAmount
                                    : patient.currentAmount,
                        totalAmount: patient.amount,
                      );
                    },
                  ),

发射器

_onSetPatientCardFromSoketEvent(
      SetPatientCardFromSoketEvent event, Emitter<PatientCardState> emit) {
    final patient = event.patient;
    if (state.patient.id == patient.id) {
      emit(PatientCardState(
          patient: patient, status: PatientCardStatus.initialized));
    }
  }
zour9fqk

zour9fqk1#

阻塞:患者卡阻塞()
在定义BlocBuilder时不应创建新的Bloc对象。请改用BlocProvider的create方法。

相关问题