postcomments method

Future<void> postcomments(
  1. Post post,
  2. TextEditingController messageController, {
  3. required dynamic profileFunction({
    1. required Media? avatar,
    2. required Media? banner,
    3. required String? displayname,
    4. required int userID,
    5. required String username,
    }),
})

Implementation

Future<void> postcomments(
  Post post,
  TextEditingController messageController, {
  required Function({
    required int userID,
    required String username,
    required String? displayname,
    required Media? avatar,
    required Media? banner,
  }) profileFunction,
}) async {
  Rxn<List<APIPostComments>> comments = Rxn<List<APIPostComments>>();

  //Yorumları Çekmeye başla
  getcommentsfetch(comments, post.postID);

  showModalBottomSheet(
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.vertical(
        top: Radius.circular(10),
      ),
    ),
    isScrollControlled: true,
    backgroundColor: Get.theme.cardColor,
    context: Get.context!,
    builder: (BuildContext context) {
      return FractionallySizedBox(
        heightFactor: 0.8,
        child: RefreshIndicator(
          onRefresh: () async => await getcommentsfetch(
            comments,
            post.postID,
            fetchRestart: true,
          ),
          child: SafeArea(
            child: Column(
              children: [
                const SizedBox(height: 10),
                CustomText.costum1(
                  SocialKeys.socialComments.tr.toUpperCase(),
                ),
                const SizedBox(height: 5),
                const Divider(),
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Container(
                      alignment: Alignment.center,
                      child: Obx(
                        () => comments.value == null
                            ? Column(
                                children: [
                                  ShimmerPlaceholder.listTilePlaceholder(
                                    trailingIcon: const Icon(Icons.favorite),
                                  ),
                                  ShimmerPlaceholder.listTilePlaceholder(
                                    trailingIcon: const Icon(Icons.favorite),
                                  ),
                                  ShimmerPlaceholder.listTilePlaceholder(
                                    trailingIcon: const Icon(Icons.favorite),
                                  ),
                                  ShimmerPlaceholder.listTilePlaceholder(
                                    trailingIcon: const Icon(Icons.favorite),
                                  ),
                                  ShimmerPlaceholder.listTilePlaceholder(
                                    trailingIcon: const Icon(Icons.favorite),
                                  ),
                                ],
                              )
                            : comments.value!.isEmpty
                                ? CustomText.costum1(
                                    SocialKeys.socialWriteFirstComment.tr,
                                  )
                                : ListView.builder(
                                    itemCount: comments.value!.length,
                                    itemBuilder: (context, index) {
                                      return PostcommentView
                                          .postCommentsWidgetV2(
                                        context,
                                        service,
                                        comments.value![index],
                                        profileFunction: profileFunction,
                                        deleteFunction: () {
                                          comments.value!.removeAt(index);

                                          comments.refresh();
                                        },
                                      );
                                    },
                                  ),
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(
                    bottom: MediaQuery.of(Get.context!).viewInsets.bottom,
                  ),
                  child: Row(
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: CircleAvatar(
                          backgroundColor: Colors.transparent,
                          foregroundImage: CachedNetworkImageProvider(
                            currentUser!.avatar!.mediaURL.minURL.value,
                          ),
                          radius: 20,
                        ),
                      ),
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          padding: const EdgeInsets.all(5),
                          height: 55,
                          child: Center(
                            child: Container(
                              padding: const EdgeInsets.only(left: 5),
                              decoration: BoxDecoration(
                                color: Get.theme.scaffoldBackgroundColor,
                                borderRadius: BorderRadius.circular(10.0),
                              ),
                              child: TextField(
                                controller: messageController,
                                style: const TextStyle(
                                    color: Colors.white, fontSize: 16),
                                decoration: InputDecoration(
                                  hintText: SocialKeys.socialWriteComment.tr,
                                  border: InputBorder.none,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ),
                      Container(
                        padding: const EdgeInsets.all(5.0),
                        child: ElevatedButton(
                          onPressed: () async {
                            PostCreateCommentResponse response =
                                await service.postsServices.createcomment(
                              postID: post.postID,
                              text: messageController.text,
                            );
                            if (!response.result.status) {
                              ARMOYUWidget.toastNotification(
                                  response.result.description.toString());
                              return;
                            }
                            await getcommentsfetch(
                              comments,
                              post.postID,
                              fetchRestart: true,
                            );
                            messageController.text = "";
                          },
                          child: const Icon(
                            Icons.send,
                            size: 16,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    },
  );
  return;
}