Untitled
unknown
dart
3 years ago
30 kB
1
Indexable
Never
import 'package:cached_network_image/cached_network_image.dart'; import 'package:carousel_slider/carousel_slider.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/svg.dart'; import 'package:get/get.dart'; import 'package:iketfaa_delivery/App/Common/Services/AuthenticationService/Core/manager.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/ButtonWithBorder.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/ActiveOrder.dart'; import 'package:iketfaa_delivery/App/Delivery/Models/Main/DeliveryHomeTopBannerItem.dart'; import 'package:iketfaa_delivery/App/Delivery/Models/Main/DriverNewOffer.dart'; import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryDriverActiveOrder/binding/delivery_driver_active_order_binding.dart'; import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryDriverActiveOrder/controller/delivery_driver_active_order_controller.dart'; import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryDriverActiveOrder/view/delivery_driver_active_order_details_view.dart'; import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryOrderChat/binding/DeliveryActiveOrderChatBinding.dart'; import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryOrderChat/views/DeliveryActiveOrderChatView.dart'; import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/primary_app_bar.dart'; class DeliveryDriverActiveOrderView extends GetView<DeliveryDriverActiveOrderController> { @override Widget build(BuildContext context) { return SafeArea( top: false, child: Scaffold( backgroundColor: AppColors.white, appBar: PrimaryAppBar( title: "activeOrder", icon: "assets/svg/menu.svg", iconColor: AppColors.black, function: () => Scaffold.of(context).openDrawer(), ), body: Obx( () => controller.authManager.deliveryUser.value.driver == null ? CustomShimmerEffect.rectangular(height: 100) : DeliveryDriverActiveOrderHomeView(), ))); } } /* */ class DeliveryDriverActiveOrderHomeView extends GetView<DeliveryDriverActiveOrderController> { @override Widget build(BuildContext context) { return Container( width: Get.width, child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( height: 20.0, ), Container( width: Get.width * 0.8, child: Column( children: [ 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), ), ), ) ], ); }), SizedBox( height: 30.0, ), Container( padding: EdgeInsets.all(10.0), decoration: BoxDecoration( color: AppColors.lightGreyColor, borderRadius: BorderRadius.circular(8.0)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'switchToCustomer'.tr, style: Get.textTheme.headline5, ), SizedBox( height: 5.0, ), Text( 'becomeClient'.tr, style: Get.textTheme.bodyText2!.copyWith( color: AppColors.primary, fontWeight: FontWeight.bold), ), ], ), CupertinoSwitch( activeColor: AppColors.primaryDark, value: controller .authManager.deliveryUser.value.userMode == 0, onChanged: (value) async { if (controller.authManager.deliveryUser.value .driver!.activeTrip != null) { return controller.authManager.commonTools .ShowWarningDialogSingleButton( context, 'failed'.tr, 'youAreOnActiveTripYouCannotConvertToClient' .tr, 'ok'.tr, AppColors.red, () { Navigator.pop(context); }); } if (value) controller.authManager.commonTools.showLoading(); bool result = await controller .deliveryHubController.updateDatabase .updateUserSingleField(USER_MODE_FIELD, 0); if (result) { controller.authManager.deliveryUser .update((deliveryUser) { deliveryUser!.userMode = 0; }); } Get.back(); }) ], ), ), SizedBox( height: 30.0, ), Container( width: Get.width, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SvgPicture.asset( 'assets/svg/activeOrder.svg', color: AppColors.primary, ), SizedBox( width: 10.0, ), Text( 'activeOrder'.tr, style: Get.textTheme.headline5!.copyWith( fontWeight: FontWeight.bold, color: AppColors.darkGrey.withOpacity(0.8)), ) ], ), ), SizedBox( height: 30.0, ), Obx(() => controller.authManager.deliveryUser.value.driver! .activeTrip == null ? Container( margin: EdgeInsets.only(top: 20.0), child: NoItemsEmpty( icon: SvgPicture.asset( "assets/svg/box.svg", width: 80.0, ), message: 'noCurrentOrderMessage'), ) : controller.authManager.deliveryUser.value.driver! .activeTrip == null ? Container() : StreamBuilder<DocumentSnapshot>( key: Key('DriverCurrentOrder'), stream: FirebaseFirestore.instance .collection(DELIVERY_NEW_ORDERS_COLLECTION) .doc(controller.authManager.deliveryUser.value .driver!.activeTrip) .snapshots(), builder: (context, snapshot) { if (snapshot.data == null) { return Container(); } if (!snapshot.hasData) { return Container(); } if (snapshot.data!.data() == null) { return Container(); } controller.driverActiveOrder = ActiveOrder.fromJson(snapshot.data!.data() as Map<String, dynamic>); return Container( padding: const EdgeInsets.all(10.0), decoration: BoxDecoration( color: AppColors.white, borderRadius: BorderRadius.circular(10.0), boxShadow: [AppStyles.primaryShadow]), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ CircleAvatar( foregroundColor: AppColors.backgroundColor, backgroundColor: AppColors.backgroundColor, backgroundImage: NetworkImage( controller .authManager.commonTools .getUserProfilePicture( controller .driverActiveOrder .customerID ?? ''), ), radius: 25.0, ), SizedBox( width: 10.0, ), Container( width: Get.width * 0.35, child: Column( children: [ Text( controller.driverActiveOrder .customerName ?? '', style: Get.textTheme.headline5, ), ], ), ) ], ), Container( padding: const EdgeInsets.all(5.0), decoration: BoxDecoration( color: AppColors.primary .withOpacity(0.4), borderRadius: BorderRadius.circular(5.0)), child: Row( children: [ SvgPicture.asset( 'assets/svg/activeOrder.svg', color: AppColors.primary, ), SizedBox( width: 3.0, ), Text( 'delivering'.tr, style: Get .textTheme.subtitle1! .copyWith( color: AppColors.primary, fontWeight: FontWeight.bold), ), ], )), ], ), SizedBox( height: 10.0, ), Row( children: [ Text( 'orderID'.tr + ':', style: Get.textTheme.subtitle1, ), Text( ' #${controller.driverActiveOrder.orderID}', style: Get.textTheme.subtitle1! .copyWith( fontWeight: FontWeight.w600), ), ], ), SizedBox( height: 5.0, ), Row( mainAxisSize: MainAxisSize.min, children: [ Expanded( child: ButtonWithBorder( background: AppColors.white, function: () { Get.to( () => DeliveryDriverActiveOrderDetailsView(), binding: DeliveryDriverActiveOrderBindings()); }, text: 'Order Details'.tr, border: AppColors.primary, padding: 3.0, width: double.infinity, textColor: AppColors.black, borderSideWidth: 1.0, ), ), SizedBox( width: 5.0, ), Expanded( child: ButtonWithBorder( background: AppColors.white, function: () { Get.to( () => DeliveryActiveOrderChatView(), binding: DeliveryActiveOrderChatBinding(), arguments: [ controller .driverActiveOrder, DriverOffer( driverID: controller .authManager .appUser .value .id, driverName: controller .authManager .appUser .value .name, rate: controller .authManager .appUser .value .rating, mobileNumber: controller .authManager .appUser .value .phoneNumber), ]); }, text: 'chat'.tr, border: AppColors.primary, padding: 3.0, width: double.infinity, textColor: AppColors.black, borderSideWidth: 1.0, ), ), ], ) ], ), ); }, )) ], ), ), ], ), ); } }