1

in view file the controller is initialized as

  SelectCalenderController selectCalenderController =
        Get.put(SelectCalenderController());

Here is the code for view file listview builder

Obx(() {
                          log("list view 1 ${selectCalenderController.appointmentDoctorModel.value.data?.onlineAppointment.length}");
                          return selectCalenderController.isL.value
                              ? circularProgressIndicator()
                              : SizedBox(
                                  height: 159,
                                  width: 400,
                                  child: ListView.builder(
                                    physics: BouncingScrollPhysics(),
                                    itemCount: selectCalenderController
                                            .appointmentDoctorModel
                                            .value
                                            .data
                                            ?.onlineAppointment
                                            .length ??
                                        0,
                                    itemBuilder: (context, index) {
                                      log("list view 123456 ${selectCalenderController.appointmentDoctorModel.value.data?.onlineAppointment.length}");
                                      return Center(
                                        child: Padding(
                                          padding: const EdgeInsets.all(8.0),
                                          child: GestureDetector(
                                            onTap: () {},
                                            child: Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment
                                                      .spaceBetween,
                                              children: [
                                                Row(
                                                  children: [
                                                    Text(
                                                      "${selectCalenderController.appointmentDoctorModel.value.data?.onlineAppointment[index].name.toString()}",
                                                      style: TextStyle(
                                                        fontSize: 16.0,
                                                        color: Colors.black54,
                                                      ),
                                                    ),
                                                    Text(
                                              "${selectCalenderController.appointmentDoctorModel.value.data?.onlineAppointment[index].slotTiming.toString()}",
                                                      style: TextStyle(
                                                        fontSize: 16.0,
                                                        color: Colors.black54,
                                                      ),
                                                    ),
                                                  ],
                                                ),
                                                Row(
                                                  children: const [
                                                    Text(
                                                      'Online',
                                                      style: TextStyle(
                                                        fontSize: 15.0,
                                                        color:
                                                            Color(0xff27767c),
                                                      ),
                                                    ),
                                                  ],
                                                ),
                                              ],
                                            ),
                                          ),
                                        ),
                                      );
                                    },
                                  ),
                                );
                        })

the code for controller is

 class SelectCalenderController extends GetxController {
  RxBool isLoading = false.obs;

  Rx<ClinicDcotorDetailModel> clinicDcotorDetailModel =
      ClinicDcotorDetailModel(data: null).obs;

  Future<void> clinicDoctorDetailsFetch(int id) async {
    try {
      isLoading(true);
      Response response = await DioClinetToken.instance.dio!.get(
        "api",
      );
      if (response.statusCode == 200) {
        print("great");
        clinicDcotorDetailModel.value =
            ClinicDcotorDetailModel.fromJson(response.data);
        print("added");
        print(clinicDcotorDetailModel);
        // log(clinicDcotorDetailModel.toString());
      }
    } catch (e) {
      log(e.toString());
    } finally {
      isLoading(false);
    }
  }

  Rx<AppointmentDoctor> appointmentDoctorModel = AppointmentDoctor().obs;
  RxList<OnlineAppointment> onlineAppointment = <OnlineAppointment>[].obs;
  RxBool isL = false.obs;
  Future<void> doctorFethcDateQueary(
      {required int clinicId, required int drId, required String date}) async {
    isL(true);
    try {
      Response response = await DioClinetToken.instance.dio!
          .get("api");
      if (response.statusCode == 200) {
        appointmentDoctorModel.value =
            AppointmentDoctor.fromJson(response.data);
        onlineAppointment.value = OnlineAppointment.fromJsonList(
            response.data['data']['online_appointment']);
        print(onlineAppointment);
        print("data in calender added");
        print(response);
        print(appointmentDoctorModel.value.data?.onlineAppointment.length);
      }
    } on DioError catch (e) {
      log(e.toString());
      if (e.type == DioErrorType.other) {
        Get.snackbar(
          "Internet Error",
          "Please Check Your Internet Connection",
          colorText: CupertinoColors.white,
          backgroundColor: CupertinoColors.destructiveRed,
        );
      } else if (e.response?.statusCode == 500) {
        Get.snackbar(
          "Error",
          "Something went wrong please try again later",
          colorText: CupertinoColors.white,
          backgroundColor: CupertinoColors.destructiveRed,
        );
      } else if (e.response?.statusCode == 401) {
        Get.snackbar(
          "Error",
          "${e.response?.data["data"]["errors"]}",
          colorText: CupertinoColors.white,
          backgroundColor: CupertinoColors.destructiveRed,
        );
      }
    } finally {
      isL.value = false;
    }
  }

  @override
  void onInit() {
    clinicDoctorDetailsFetch(10);

    /// change here dynamic
    super.onInit();
  }
}

in it the controller is workign fine justt in the view part there is no updateing

i need that in there i wanted that choosing date it calls the following code and update that listview builder

code for select date is

 _selectDate(BuildContext context,
      {required int clinicId, required int drId, required String date}) async {
    final DateTime? selected = await showDatePicker(
      context: context,
      initialDate: DateTime.now(),
      firstDate: DateTime(2020),
      lastDate: DateTime(2035),
    );
    if (selected != null && selected != selectedDate) {
      setState(
        () {
          selectedDate = selected;
          _textEditingController
            ..text = DateFormat.yMMMd().format(selectedDate)
            ..selection = TextSelection.fromPosition(
              TextPosition(
                  offset: _textEditingController.text.length,
                  affinity: TextAffinity.upstream),
            );
        },
      );
      // log(DateFormat.yMMMd().format(selectedDate).toString());
      await SelectCalenderController()
          .doctorFethcDateQueary(clinicId: clinicId, drId: drId, date: date);
    }
  }

0 Answers0