Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
29 kB
1
Indexable
Never
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:dots_indicator/dots_indicator.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:iketfaa_delivery/App/Common/Modules/SignIn/binding/signin_binding.dart';
import 'package:iketfaa_delivery/App/Common/Modules/SignIn/view/signin_view.dart';
import 'package:iketfaa_delivery/App/Common/Services/translation_service.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppColors.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppStyles.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/Strings/Backend.dart';
import 'package:iketfaa_delivery/App/Common/Widgets/CustomShimmerEffect.dart';
import 'package:iketfaa_delivery/App/Common/Widgets/no_items_empty.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/DeliveryHomeTopBannerItem.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/PersonalAddress.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryHome/controller/delivery_home_controller.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryUser/DeliveryUserAddressBook/binding/delivery_address_book_binding.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryUser/DeliveryUserAddressBook/view/delivery_add_new_address_view.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/NewOrder/binding/delivery_new_order_binding.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/NewOrder/view/delivery_new_order_view.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/Stores/binding/delivery_stores_binding.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/Stores/view/delivery_stores_view.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/StoresSearch/binding/delivery_stores_search_binding.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/StoresSearch/view/delivery_stores_search_view.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/Drawer/delivery_tile_button_for_drawer.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/LocationTile.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/delivery_home_appbar.dart';

class DeliveryHomeView extends GetView<DeliveryHomeController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.white,
      resizeToAvoidBottomInset: false,
      appBar: DeliveryHomeAppBar(
        drawerFunction: () => Scaffold.of(context).openDrawer(),
        deliverToFunction: () {
          controller.authManager.commonTools.showCustomBottomSheet(
              context,
              controller.authManager.isLogged.value
                  ? "chooseDeliveryLocation".tr
                  : 'pleaseSignIn'.tr,
              controller.authManager.isLogged.value
                  ? StreamBuilder<QuerySnapshot>(
                      stream: FirebaseFirestore.instance
                          .collection(DELIVERY_USERS_COLLECTION)
                          .doc(controller.authManager.appUser.value.id)
                          .collection(PERSONAL_ADDRESS_COLLECTION)
                          .orderBy(DATE_FIELD, descending: true)
                          .snapshots(),
                      builder: (context, snapshot) {
                        if (snapshot.data == null) {
                          return Container(
                            height: Get.width * 0.6,
                            width: Get.width,
                            child: CupertinoActivityIndicator(),
                          );
                        }
                        if (!snapshot.hasData) {
                          return Container(
                            height: Get.width * 0.6,
                            width: Get.width,
                            child: CupertinoActivityIndicator(),
                          );
                        }
                        return !snapshot.data!.docs.isEmpty
                            ? Container(
                                height: Get.width * 0.8,
                                padding: EdgeInsets.symmetric(horizontal: 25),
                                child: ListView(
                                  shrinkWrap: true,
                                  children: [
                                    Container(
                                      child: ListView.builder(
                                        shrinkWrap: true,
                                        physics: NeverScrollableScrollPhysics(),
                                        itemCount: snapshot.data!.docs.length,
                                        itemBuilder: (context, index) {
                                          DocumentSnapshot doc =
                                              snapshot.data!.docs[index];
                                          PersonalAddress? address =
                                              PersonalAddress.fromMap(doc.data()
                                                  as Map<String, dynamic>);
                                          return LocationTile(
                                            withCricle: true,
                                            address: address,
                                            active: controller
                                                    .deliveryHubController
                                                    .currentPersonalAddress
                                                    .value
                                                    .adID ==
                                                address.adID,
                                            onTap: () {
                                              controller
                                                  .deliveryHubController
                                                  .currentPersonalAddress
                                                  .value = address;
                                              Get.back();
                                            },
                                          );
                                        },
                                      ),
                                    ),
                                    ListTile(
                                      onTap: () {
                                        controller.homeAddressFlag.value = true;
                                        Get.to(
                                          () => DeliveryAddNewAddressView(),
                                          binding: DeliveryAddressBookBinding(),
                                        );
                                      },
                                      title: Text('addNewAddress'.tr,
                                          style: Get.textTheme.headline4),
                                      leading: SvgPicture.asset(
                                        'assets/svg/gen011-021.svg',
                                        width: 25,
                                      ),
                                    ),
                                    Divider(),
                                    ListTile(
                                      onTap: () {
                                        controller
                                            .deliveryHubController
                                            .currentPersonalAddress
                                            .value = PersonalAddress();
                                        Get.back();
                                      },
                                      title: Text('currentLocation'.tr,
                                          style: Get.textTheme.headline4),
                                      leading: SvgPicture.asset(
                                        'assets/svg/gen011-021.svg',
                                        width: 25,
                                      ),
                                    )
                                  ],
                                ),
                              )
                            : Container(
                                padding: EdgeInsets.all(10),
                                child: Column(
                                  children: [
                                    ListTile(
                                      onTap: () {
                                        controller.homeAddressFlag.value = true;
                                        Get.to(
                                          () => DeliveryAddNewAddressView(),
                                          binding: DeliveryAddressBookBinding(),
                                        );
                                      },
                                      title: Text('addNewAddress'.tr,
                                          style: Get.textTheme.headline4),
                                      leading: SvgPicture.asset(
                                        'assets/svg/gen011-021.svg',
                                        width: 25,
                                      ),
                                    ),
                                    Divider(),
                                    ListTile(
                                      onTap: () {
                                        controller
                                            .deliveryHubController
                                            .currentPersonalAddress
                                            .value = PersonalAddress();
                                        Get.back();
                                      },
                                      title: Text('currentLocation'.tr,
                                          style: Get.textTheme.headline4),
                                      leading: SvgPicture.asset(
                                        'assets/svg/gen011-021.svg',
                                        width: 25,
                                      ),
                                    )
                                  ],
                                ),
                              );
                      },
                    )
                  : Column(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        Container(
                          height: 10,
                          color: AppColors.white,
                        ),
                        Container(
                          color: AppColors.white,
                          child: Column(
                            children: [
                              DelvieryTileButtonForDrawer(
                                title: 'login'.tr,
                                onTap: () {
                                  Get.offAll(() => SignInView(),
                                      binding: SignInBinding());
                                },
                                icon:
                                    Icon(Icons.login, color: AppColors.primary),
                              ),
                              Container(
                                height: 30,
                                color: AppColors.white,
                              ),
                            ],
                          ),
                        ),
                      ],
                    ));
        },
        width: Get.width * 0.8,
      ),
      body: Center(
        child: Container(
          width: Get.width * 0.8,
          child: ListView(
            padding: EdgeInsets.zero,
            children: [
              const SizedBox(height: 20.0),
              FutureBuilder<QuerySnapshot>(
                  future: FirebaseFirestore.instance
                      .collection(UTILITIES_COLLECTION)
                      .doc(DELIVERY_ADMIN_OPTIONS_DOC)
                      .collection(DELIVERY_HOME_BANNERS_COLLECTION)
                      .orderBy(DATE_FIELD, descending: true)
                      .get(),
                  builder: (context, snapshot) {
                    if (snapshot.data == null) {
                      return CustomShimmerEffect.rectangular(height: 200);
                    }
                    if (!snapshot.hasData) {
                      return CustomShimmerEffect.rectangular(height: 200);
                    }
                    return Stack(
                      children: [
                        CarouselSlider.builder(
                            options: CarouselOptions(
                                autoPlay: true,
                                enlargeCenterPage: true,
                                viewportFraction: 1,
                                aspectRatio: 1.8,
                                initialPage: 0,
                                onPageChanged: (index, reason) {
                                  controller.deliveryHubController.currentPos
                                      .value = index;
                                }),
                            itemCount: snapshot.data!.docs.length,
                            itemBuilder: (BuildContext context, int itemIndex,
                                int pageViewIndex) {
                              DeliveryHomeTopBannerItem
                                  deliveryHomeTopBannerItem =
                                  DeliveryHomeTopBannerItem.fromJson(
                                      snapshot.data!.docs[itemIndex].data()
                                          as Map<String, dynamic>);

                              return Container(
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                child: InkWell(
                                  onTap: () {
                                    controller.authManager.commonTools.openURL(
                                        deliveryHomeTopBannerItem.onTapLink!);
                                  },
                                  child: IgnorePointer(
                                    child: Stack(
                                      children: [
                                        Positioned.fill(
                                          child: Container(
                                            decoration: BoxDecoration(
                                                borderRadius:
                                                    BorderRadius.circular(15.0),
                                                image: DecorationImage(
                                                    fit: BoxFit.cover,
                                                    image: CachedNetworkImageProvider(
                                                        deliveryHomeTopBannerItem
                                                            .imagePath!))),
                                          ),
                                        ),
                                        Container(
                                          decoration: BoxDecoration(
                                            color: AppColors.black
                                                .withOpacity(0.6),
                                            borderRadius:
                                                BorderRadius.circular(15.0),
                                          ),
                                        ),
                                        Align(
                                            alignment: Alignment.bottomCenter,
                                            child: Container(
                                                margin: EdgeInsets.only(
                                                    bottom: 50.0),
                                                decoration: BoxDecoration(
                                                  borderRadius:
                                                      BorderRadius.circular(
                                                          15.0),
                                                ),
                                                child: Column(
                                                  mainAxisAlignment:
                                                      MainAxisAlignment.end,
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.start,
                                                  children: [
                                                    Center(
                                                      child: Text(
                                                        TranslationService()
                                                                .isLocaleArabic()
                                                            ? deliveryHomeTopBannerItem
                                                                .titleAr!
                                                            : deliveryHomeTopBannerItem
                                                                .titleEn!,
                                                        style: Get.textTheme
                                                            .headline3!
                                                            .copyWith(
                                                                color: AppColors
                                                                    .white,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w600),
                                                      ),
                                                    ),
                                                    SizedBox(
                                                      height: 10.0,
                                                    ),
                                                    Center(
                                                      child: Text(
                                                        TranslationService().isLocaleArabic()
                                                            ? deliveryHomeTopBannerItem
                                                                .subtitleAr!
                                                            : deliveryHomeTopBannerItem
                                                                .subtitleEn!,
                                                        style: Get.textTheme
                                                            .headline6!
                                                            .copyWith(
                                                                color: AppColors
                                                                    .white,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w600),
                                                      ),
                                                    ),
                                                  ],
                                                )))
                                      ],
                                    ),
                                  ),
                                ),
                              );
                            }),
                        Positioned.fill(
                          child: Align(
                            alignment: Alignment.bottomCenter,
                            child: Obx(
                              () => Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  DotsIndicator(
                                    dotsCount: snapshot.data!.docs.length,
                                    position: controller
                                        .deliveryHubController.currentPos.value
                                        .toDouble(),
                                    decorator: DotsDecorator(
                                      color: AppColors.shadow, // Inactive color
                                      activeColor: AppColors.white,
                                    ),
                                  ),
                                ],
                              ).marginOnly(bottom: 10.0),
                            ),
                          ),
                        )
                      ],
                    );
                  }),
              const SizedBox(height: 20.0),
              GestureDetector(
                onTap: () {
                  Get.to(() => DeliveryStoresSearchView(),
                      binding: DeliveryStoresSearchBinding());
                },
                child: Container(
                    margin: EdgeInsets.all(5.0),
                    decoration: BoxDecoration(
                      color: AppColors.white,
                      borderRadius: BorderRadius.circular(30.0),
                      boxShadow: [
                        AppStyles.primaryShadow,
                      ],
                    ),
                    child: Padding(
                      padding: const EdgeInsets.all(10.0),
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Text(
                            'search_stores'.tr,
                            style: Get.textTheme.headline6!.copyWith(
                              color: AppColors.grey.withOpacity(0.8),
                              fontWeight: FontWeight.w600,
                            ),
                          ),
                          Expanded(child: SizedBox()),
                          SvgPicture.asset("assets/svg/search.svg"),
                        ],
                      ),
                    )),
              ),
              const SizedBox(height: 20.0),
              Padding(
                padding: const EdgeInsets.symmetric(
                    horizontal: 10.0, vertical: 10.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('categories'.tr,
                        style: Get.textTheme.headline3!
                            .copyWith(fontWeight: FontWeight.w600)),
                    InkWell(
                      onTap: () {
                        Get.to(
                            () => DeliveryNewOrderView(
                                  title: 'directOrder',
                                ),
                            binding: DeliveryNewOrderBinding());
                      },
                      child: Text('directOrder'.tr,
                          style: Get.textTheme.headline4!.copyWith(
                              color: AppColors.primary,
                              fontWeight: FontWeight.w700)),
                    ),
                  ],
                ),
              ),
              GridView.count(
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
                padding: const EdgeInsets.symmetric(
                    horizontal: 10.0, vertical: 10.0),
                childAspectRatio: 1,
                crossAxisSpacing: 35.0,
                mainAxisSpacing: 15.0,
                crossAxisCount: 2,
                children: [
                  HomeGridWhiteButton(
                    onPressed: () {
                      Get.to(() => DeliveryStoresView(),
                          arguments: [
                            "restaurant",
                            "restaurants",
                            "assets/img/resturant_bg.jpg"
                          ],
                          binding: DeliveryStoresBinding());
                    },
                    title: 'resturant'.tr,
                    icon: "assets/svg/restaurants.svg",
                  ),
                  HomeGridWhiteButton(
                    onPressed: () {
                      Get.to(() => DeliveryStoresView(),
                          arguments: [
                            'supermarket',
                            'supermarkets',
                            'assets/img/supermarkets_bg.jpg'
                          ],
                          binding: DeliveryStoresBinding());
                    },
                    title: 'supermarkets'.tr,
                    icon: "assets/svg/supermarkets.svg",
                  ),
                  HomeGridWhiteButton(
                    onPressed: () {
                      Get.to(() => DeliveryStoresView(),
                          arguments: [
                            'electronics_store',
                            'electronics',
                            'assets/img/electronics_bg.jpg'
                          ],
                          binding: DeliveryStoresBinding());
                    },
                    title: 'electronics'.tr,
                    icon: "assets/svg/electronics.svg",
                  ),
                  HomeGridWhiteButton(
                    onPressed: () {
                      Get.to(() => DeliveryStoresView(),
                          arguments: [
                            'pharmacy',
                            'pharmacy',
                            'assets/img/pharmacy_bg.jpg'
                          ],
                          binding: DeliveryStoresBinding());
                    },
                    title: 'pharmacy'.tr,
                    icon: "assets/svg/pharmacy.svg",
                  ),
                  HomeGridWhiteButton(
                    onPressed: () {
                      Get.to(() => DeliveryStoresView(),
                          arguments: [
                            'florist',
                            'florist',
                            'assets/img/florist_bg.jpg'
                          ],
                          binding: DeliveryStoresBinding());
                    },
                    title: 'florist'.tr,
                    icon: "assets/svg/florist.svg",
                  ),
                  HomeGridWhiteButton(
                    onPressed: () {
                      Get.to(() => DeliveryStoresView(),
                          arguments: [
                            'laundry',
                            'laundry',
                            'assets/img/laundry_bg.jpg'
                          ],
                          binding: DeliveryStoresBinding());
                    },
                    title: 'laundry'.tr,
                    icon: "assets/svg/laundry.svg",
                  ),
                ],
              ),
              SizedBox(height: Get.height * 0.15)
            ],
          ),
        ),
      ),
    );
  }
}

class HomeGridWhiteButton extends StatelessWidget {
  final VoidCallback onPressed;
  final String title;
  final String icon;

  const HomeGridWhiteButton({
    required this.onPressed,
    required this.title,
    required this.icon,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10.0),
        color: AppColors.white,
        boxShadow: [
          AppStyles.primaryShadow,
        ],
      ),
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onPressed,
          customBorder: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10.0),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SvgPicture.asset(icon),
              SizedBox(height: 10),
              Text(
                title.tr,
                style: Get.textTheme.bodyText1!
                    .copyWith(fontWeight: FontWeight.w700),
              )
            ],
          ),
        ),
      ),
    );
  }
}