Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
5.0 kB
1
Indexable
Never
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:iketfaa_delivery/App/Common/Modules/MyProfile/controller/my_profile_controller.dart';
import 'package:iketfaa_delivery/App/Common/Modules/MyProfile/widget/my_profile_header.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppColors.dart';
import 'package:iketfaa_delivery/App/Common/Widgets/PostItemWidget.dart';
import 'package:iketfaa_delivery/App/Freelance/Models/Main/UserPostItem.dart';

class MyProfileView extends GetView<MyProfileController> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      initialIndex: 0,
      length: 2,
      child: Scaffold(
        backgroundColor: AppColors.backgroundColor,
        body: NotificationListener<ScrollNotification>(
          onNotification: (ScrollNotification scrollInfo) {
            if (!controller.isLoading.value &&
                scrollInfo.metrics.pixels ==
                    scrollInfo.metrics.maxScrollExtent &&
                controller.notCached.value) {
              controller.isLoading.value = true;

              Future.delayed(const Duration(milliseconds: 100), () async {
                List<UserPostItem> list = <UserPostItem>[];
                list = await controller.authManager.api
                    .getUserNext12Posts(controller.postsPageIndex.value);
                controller.isLoading.value = false;

                if (list.length != 0) {
                  controller.postsPageIndex.value += 1;
                  controller.userPosts.addAll(list);
                } else {
                  controller.notCached.value = false;
                  controller.postsPageIndex.value = 2;
                }
              });

              return true;
            }

            return false;
          },
          child: ListView(
            padding: EdgeInsets.zero,
            children: [
              MyProfileHeader(),
              TabBar(
                isScrollable: false,
                indicatorColor: AppColors.primary,
                labelColor: AppColors.black,
                labelStyle: Get.textTheme.headline6!
                    .copyWith(fontWeight: FontWeight.w500),
                tabs: [
                  Tab(
                    text: 'posts'.tr,
                  ),
                  Tab(text: 'videos'.tr),
                ],
                controller: controller.tabController.value,
                onTap: (index) {
                  controller.tabIndex.value = index;
                },
              ),
              Obx(
                () => controller.tabIndex.value == 0
                    ? controller.userPosts.isEmpty
                        ? Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Center(
                                child: Text(
                                  "You don't have any posts yet".tr,
                                  style: Get.textTheme.headline5,
                                ),
                              ),
                            ],
                          )
                        : GridView.builder(
                            shrinkWrap: true,
                            scrollDirection: Axis.vertical,
                            padding: EdgeInsets.zero,
                            physics: const NeverScrollableScrollPhysics(),
                            addAutomaticKeepAlives: true,
                            addRepaintBoundaries: false,
                            gridDelegate:
                                const SliverGridDelegateWithFixedCrossAxisCount(
                              crossAxisCount: 3,
                            ),
                            cacheExtent: Get.width * 0.25,
                            itemCount: controller.userPosts.length,
                            itemBuilder: (context, indexPath) {
                              return PostItemWidget(
                                postItem: controller.userPosts[indexPath],
                              );
                            },
                          )
                    : const Center(
                        child: Text('Qanati Videos'),
                      ),
              ),

              // Visibility(
              //   visible: controller.notCached.value,
              //   child: Container(
              //     margin: const EdgeInsets.only(top: 10.0, bottom: 10.0),
              //     width: Get.width,
              //     height: 30.0,
              //     child: Visibility(
              //         visible: controller.isLoading.value,
              //         child: const CupertinoActivityIndicator()),
              //   ),
              // )
            ],
          ),
        ),
      ),
    );
  }
}