当我的列表充满数据时如何更新 ui GetX Flutter

How to update the ui when my list gets filled with data GetX Flutter

我试图在 AlertDialog 中显示 listView.builder,我每次都通过调用一个函数来填充它的列表按下打开 AlertDialog 的按钮,但问题是当列表中充满数据时 ui 不会更新,我正在使用 getX 并且我'我对它很陌生,有人可以告诉我我做错了什么吗?

我正在使用 GetX builder:

GetX<DashboardController>(
            init: Get.put<DashboardController>(DashboardController()),
            builder: (DashboardController dashboardController) {
              return GridView.builder(

我的Get.dialog函数:

                  return GestureDetector(
                    onTap: () {
                      // this is where I'm filling the list
                      dashboardController
                          .callEmployeeCheckInOutList(_employeeModel.id);
                      Get.dialog(
                        AlertDialog(
                          contentPadding: EdgeInsets.zero,
                          content: SizedBox(
                            height: size.height * 0.55,
                            width: size.width,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                EmployeeProfileWidget(
                                  size: size,
                                  profileBackgroudPath: profileBackgroudPath,
                                  employeeModel: _employeeModel,
                                ),
                                // this is where my listview.builder resides
                                EmployeeActivityWidget(
                                  closeCrossPath: closeCrossPath,
                                  employeeCheckInOutList:
                                      _employeeCheckInOutList,
                                  employeeModel: _employeeModel,
                                  onTap: () {},
                                ),
                              ],
                            ),
                          ),
                        ),
                      );   
                    },

我的listview.builder:

 Expanded(
              child: Padding(
                padding: const EdgeInsets.only(
                  left: 32.0,
                  right: 50.0,
                ),
                child: ListView.builder(
                  itemCount: employeeCheckInOutList.length,
                  shrinkWrap: true,
                  itemBuilder: (context, index) {
                    final _checkInOutModel = employeeCheckInOutList[index];
                    return SizedBox(
                      height: 120,
                      child: TimelineTile(
                        beforeLineStyle: const LineStyle(
                          color: Color(0xffa5affb),
                        ),

我的控制器:

  Rx<List<CheckInOutModel>> _employeeCheckInOutList =
      Rx<List<CheckInOutModel>>([]);

  List<CheckInOutModel> get employeeCheckInOutList =>
      _employeeCheckInOutList.value;

  Future<void> callEmployeeCheckInOutList(String id) async {
    _employeeCheckInOutList =
        await EmployeeService.employeeCheckInOutFuture(docId: id);
    update();
  }

在 RxList 上使用 .assignAll 方法触发 UI 更新:

 Future<void> callEmployeeCheckInOutList(String id) async {
     final result = await EmployeeService.employeeCheckInOutFuture(docId: id);
     _employeeCheckInOutList.assignAll(result);
 }

并且在使用 Rx 时不需要调用 update()

我已经遇到了同样的问题。

解法:

Simply use again GetX<Controller> inside AlertDialog

喜欢

GetX<DashboardController>(
            init: Get.put<DashboardController>(DashboardController()),
            builder: (DashboardController dashboardController) {
              return GridView.builder(
              .....
              
              Get.dialog(
                    AlertDialog(
                      contentPadding: EdgeInsets.zero,
                      content:  GetX<DashboardController>(
                        init: Get.put<DashboardController>(DashboardController()),
                        builder: (DashboardController dashboardController) {
                            SizedBox(