mirrored_repositories/Flutter-Delivery-App/lib/pages
// ignore_for_file: prefer_const_constructors

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meli_melo/controllers/cart_controller.dart';
import 'package:meli_melo/controllers/popular_product_controller.dart';
import 'package:meli_melo/pages/cart/cart_page.dart';
import 'package:meli_melo/utils/app_constants.dart';
import 'package:meli_melo/widgets/app_column.dart';
import 'package:meli_melo/widgets/app_icon.dart';
import 'package:meli_melo/widgets/exandable_text_widget.dart';

import '../../routes/route_helper.dart';
import '../../utils/colors.dart';
import '../../utils/dimensions.dart';
import '../../widgets/big_text.dart';
import '../../widgets/icon_and_text_widget.dart';
import '../../widgets/small_text.dart';
import '../home/main_food_page.dart';

class PopularFoodDetail extends StatelessWidget {
  final int pageId;
  const PopularFoodDetail({ Key? key , required this.pageId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var product= Get.find<PopularProductController>().popularProductList[pageId];
    Get.find<PopularProductController>().initProduct(product, Get.find<CartController>());

    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(
        children:[
          //BACKGROUND IMAGE
          Positioned(
            left : 0,
            right : 0,
            child: Container(
              width: double.maxFinite,
              height: Dimensions.popularFoodImgSize,
              decoration: BoxDecoration(
                image : DecorationImage(
                  fit : BoxFit.cover,
                  image : NetworkImage(
                    AppConstants.BASE_URL+AppConstants.UPLOAD_URL+product.img!
                  )
                )
              ),
            )
          ),
          //ICON WIDGETS
          Positioned(
            top: Dimensions.height45,
            left: Dimensions.width20,
              right: Dimensions.width20,
              child: Row(
                mainAxisAlignment : MainAxisAlignment.spaceBetween,
                children: [
                  GestureDetector(
                    onTap:(){
                      Get.to(()=>MainFoodPage());
                      },
                      child:
                          AppIcon(icon: Icons.arrow_back_ios)
                  ),

                  GetBuilder<PopularProductController>(builder: (controller){
                    return GestureDetector(
                      onTap: (){
                        if(controller.totalItems>=1)
                        Get.toNamed(RouteHelper.getCartPage());
                      },
                      child: Stack(
                        children: [
                           AppIcon(icon: Icons.shopping_cart_checkout_outlined),
                          controller.totalItems>=1?
                            Positioned(
                              right:0, top: 0,

                                child: AppIcon(icon: Icons.circle, size: 20,
                                  iconColor: Colors.transparent,
                                  backgroundColor: Colors.red,),

                            ):
                              Container(),
                                Get.find<PopularProductController>().totalItems>=1?
                                Positioned(
                                  right:5, top: 3,
                                  child: BigText(text: Get.find<PopularProductController>().totalItems.toString(),
                                  size:12, color: Colors.white,
                                  ),
                                ):
                                Container()
                        ],
                      ),
                    );
                  })



                ],
          )),
          //INTRODUCTION TO FOOD
          Positioned(
            left: 0,
              right: 0,
              bottom: 0,
              top: Dimensions.popularFoodImgSize - 20,
              child: Container(
              padding: EdgeInsets.only(left: Dimensions.width20, right: Dimensions.width20, top: Dimensions.height20),
              decoration: BoxDecoration(
                borderRadius : BorderRadius.only(
                  topRight: Radius.circular(Dimensions.radius20),
                  topLeft : Radius.circular(Dimensions.radius20)
                ),
                color: Colors.white,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  AppColumn(text:product.name!),
                  SizedBox(height: Dimensions.height20,),
                  BigText(text: "Introduction",),
                  SizedBox(height: Dimensions.height20,),
                  Expanded(child: SingleChildScrollView(child: ExpandableTextWidget(text: product.description!)))
                ],
              ),
          ))

        ],
      ),
      bottomNavigationBar: GetBuilder<PopularProductController>(builder: (popularProduct){
        return Container(
          height: Dimensions.bottomHeightBar,
          padding: EdgeInsets.only(top: Dimensions.height20, bottom: Dimensions.height20, left: Dimensions.width20, right: Dimensions.width20),
          decoration: BoxDecoration(
              color: AppColors.buttonBackgroundColor,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(Dimensions.radius20*2),
                  topRight: Radius.circular(Dimensions.radius20*2)
              )
          ),
          child: Row(
            mainAxisAlignment:  MainAxisAlignment.spaceBetween,
            children: [
              Container(
                padding: EdgeInsets.only(top: Dimensions.height20, bottom: Dimensions.height20, left: Dimensions.width20,right: Dimensions.width20),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(Dimensions.radius20),
                    color: Colors.white
                ),
                child: Row(
                  children: [
                    GestureDetector(
                        onTap: (){
                          popularProduct.setQuantity(false);
                        },
                        child: Icon(Icons.remove, color: AppColors.SignColor,)),
                    SizedBox(width: Dimensions.width10/2,),
                    BigText(text: popularProduct.inCartItems.toString()),
                    SizedBox(width: Dimensions.width10/2,),
                    GestureDetector(
                        onTap: (){
                            popularProduct.setQuantity(true);
                        },
                        child: Icon(Icons.add, color: AppColors.SignColor,))
                  ],
                ),
              ),
              GestureDetector(
                onTap: (){
                  popularProduct.addItem(product);
                },
                child: Container(
                  padding: EdgeInsets.only(top: Dimensions.height20, bottom: Dimensions.height20, left: Dimensions.width20,right: Dimensions.width20),


                      child: BigText(text: "\$ ${product.price!} | Ajouter", color: Colors.white,),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(Dimensions.radius20),
                      color: AppColors.mainColor
                  ),
                ),
              )
            ],
          ),
        );
      },),
    );
  }
}