buildGridItem function

Widget buildGridItem(
  1. CallController controller
)

Implementation

Widget buildGridItem(CallController controller) {
  return GestureDetector(
    onTap: () {
      if (controller.callType.value == CallType.video) {
        controller.isVisible(!controller.isVisible.value);
      }
    },
    child: GridView.builder(
      scrollDirection: Axis.vertical,
      shrinkWrap: true,
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: controller.callList.length > 2
              ? 2
              : 1, // number of items in each row
          mainAxisSpacing: 4.0, // spacing between rows
          crossAxisSpacing: 2.0, // spacing between columns
          childAspectRatio: controller.callList.length == 2 ? 1.23 : 1.0),
      padding: const EdgeInsets.all(8.0),
      // padding around the grid
      itemCount: controller.callList.length,
      // total number of items
      itemBuilder: (context, index) {
        return Stack(
          children: [
            MirrorFlyView(
                key: UniqueKey(),
                userJid: controller.callList[index].userJid?.value ?? "",
                viewBgColor: AppColors.callerTitleBackground,
                profileSize: 60,
                onClick: () {
                  // if(controller.callType.value==CallType.video) {
                  controller.isVisible(!controller.isVisible.value);
                  // }
                }).setBorderRadius(const BorderRadius.all(Radius.circular(10))),
            Obx(() {
              return Positioned(
                top: 0,
                right: 8,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    // SizedBox(
                    //   width: 20,
                    //   child: CircleAvatar(
                    //     backgroundColor: AppColors.audioMutedIconBgColor,
                    //     child: SvgPicture.asset(package: package,unpinUser),
                    //   ),
                    // ),
                    if (controller.callList[index].isAudioMuted.value) ...[
                      Padding(
                        padding: const EdgeInsets.only(left: 4.0),
                        child: SizedBox(
                          width: 20,
                          child: CircleAvatar(
                            backgroundColor: AppColors.audioMutedIconBgColor,
                            child: SvgPicture.asset(
                                package: package, callMutedIcon),
                          ),
                        ),
                      ),
                    ],
                    AnimatedCrossFade(
                        firstCurve: Curves.fastOutSlowIn,
                        alignment: Alignment.center,
                        duration: const Duration(milliseconds: 300),
                        firstChild: Padding(
                          padding: const EdgeInsets.only(
                              top: 8.0, bottom: 8.0, left: 4.0),
                          child: SpeakingDots(
                            radius: 9,
                            audioLevel: controller.audioLevel(
                                controller.callList[index].userJid!.value),
                            bgColor: AppColors.speakingBg,
                          ),
                        ),
                        secondChild: const SizedBox.shrink(),
                        crossFadeState: (controller.speakingUsers.isNotEmpty &&
                                !controller
                                    .callList[index].isAudioMuted.value &&
                                !controller
                                    .audioLevel(controller
                                        .callList[index].userJid!.value)
                                    .isNegative)
                            ? CrossFadeState.showFirst
                            : CrossFadeState.showSecond)
                  ],
                ),
              );
            }),
            Positioned(
              left: 8,
              bottom: 8,
              right: 8,
              child: Obx(() {
                // debugPrint("name changed ${controller.callList[index].userJid}");
                return FutureBuilder<String>(
                    future: CallUtils.getNameOfJid(
                        controller.callList[index].userJid!.value.checkNull()),
                    builder: (context, snapshot) {
                      if (!snapshot.hasError &&
                          snapshot.data.checkNull().isNotEmpty) {
                        return Text(
                          snapshot.data.checkNull(),
                          style: const TextStyle(
                            color: Colors.white,
                            fontSize: 14,
                          ),
                          overflow: TextOverflow.ellipsis,
                          maxLines: 1,
                        );
                      }
                      return const SizedBox.shrink();
                    });
              }),
            ),
            Obx(() {
              debugPrint(
                  "getUserJID ${controller.callList[index].userJid} ${controller.callList[index].callStatus} current user ${controller.callList[index].userJid!.value == SessionManagement.getUserJID()}");
              return (getTileCallStatus(
                          controller.callList[index].callStatus?.value,
                          controller.callList[index].userJid!.value.checkNull(),
                          controller.isOneToOneCall)
                      .isNotEmpty)
                  ? Positioned.fill(
                      child: Container(
                        decoration: BoxDecoration(
                          color: Colors.black.withOpacity(
                              0.5), // Adjust the color and opacity as needed
                          borderRadius: BorderRadius.circular(10.0),
                          boxShadow: [
                            BoxShadow(
                              color: Colors.black.withOpacity(0.3),
                              blurRadius: 8,
                              offset: const Offset(0, 3),
                            ),
                          ],
                        ),
                        child: Center(
                            child: Text(
                          getTileCallStatus(
                              controller.callList[index].callStatus?.value,
                              controller.callList[index].userJid!.value
                                  .checkNull(),
                              controller.isOneToOneCall),
                          style: const TextStyle(color: Colors.white),
                        )),
                      ),
                    )
                  : const SizedBox.shrink();
            }),
            /*Obx(() {
                return (controller.callList[index].callStatus==CallStatus.ringing) ?
                  Container(color: AppColors.transBlack75, child: Center(
                  child: Text(controller.callList[index].callStatus.toString(),style: const TextStyle(color: Colors.white)),),) : const SizedBox.shrink();
              })*/
          ],
        );
      },
    ),
  );
}