import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/compare-list.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-name-and-price.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/recommended_products.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/reviews_info.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scafold_detail_page.dart'; import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import 'package:rating_bar/rating_bar.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.dart'; import '../cart-order-page.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'ProductAppBar.dart'; import 'availability_info.dart'; import 'details_info.dart'; import 'discount_description.dart'; import 'footor/footer-widget.dart'; int price = 0; bool isOverQuantity = false; bool isInWishList = false; bool isSelected = true; String itemID; var customerId; CompareList compareItems = new CompareList(); PharmacyProduct specificationData; class ProductDetailPage extends StatefulWidget { final PharmacyProduct product; ProductDetailPage(this.product); @override __ProductDetailPageState createState() => __ProductDetailPageState(); } class __ProductDetailPageState extends State with SingleTickerProviderStateMixin { TabController _tabController; AppSharedPreferences sharedPref = AppSharedPreferences(); bool isTrue = true; bool isDetails = true; bool isReviews = false; bool isAvailability = false; int _activeTab = 0; checkWishlist() async { GifLoaderDialogUtils.showMyDialog(context); ProductDetailViewModel x = new ProductDetailViewModel(); await x.checkWishlistData(); for (int i = 0; i < x.wishListItems.length; i++) { if (itemID == x.wishListItems[i].product.id) { isInWishList = true; break; } else { isInWishList = false; } } GifLoaderDialogUtils.hideDialog(context); setState(() {}); } void initState() { price = 1; specificationData = widget.product; _tabController = TabController(length: 3, vsync: this); userInfo(); super.initState(); } @override void dispose() { _tabController.dispose(); super.dispose(); } void userInfo() async { print(specificationData); customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); if (customerId != null) { itemID = widget.product.id; checkWishlist(); } setState(() {}); } Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); final screenSize = MediaQuery.of(context).size; return customerId != null ? AppScaffold( appBarTitle: TranslationBase.of(context).productDetails, isShowAppBar: true, isPharmacy: true, isShowDecPage: false, customAppBar: ProductAppBar(), body: SingleChildScrollView( child: Column( children: [ Container( width: double.infinity, color: Colors.white, child: Column( children: [ if (widget.product.images.isNotEmpty) Container( height: MediaQuery.of(context).size.height * .40, child: Image.network( widget.product.images[0].src.trim(), fit: BoxFit.contain, ), ), if (widget.product.discountDescription != null) DiscountDescription(product: widget.product) ], ), ), SizedBox( height: 4, ), Container( color: Colors.white, child: ProductNameAndPrice( context, widget.product, customerId: customerId, addToWishlistFunction: addToWishlistFunction, deleteFromWishlistFunction: deleteFromWishlistFunction, notifyMeWhenAvailable: notifyMeWhenAvailable, isInWishList: isInWishList, ), ), SizedBox( height: 6, ), Container( color: Colors.white, child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( padding: EdgeInsets.symmetric( vertical: 15, horizontal: 10), child: Texts( TranslationBase.of(context).specification, fontSize: 15, fontWeight: FontWeight.bold, ), width: double.infinity, ), // Divider(color: Colors.grey), ], ), ), SizedBox( height: 6, ), // Container( // height: 500, // color: Colors.white, // child: Scaffold( // backgroundColor: Colors.white, // extendBodyBehindAppBar: false, // appBar: PreferredSize( // preferredSize: Size.fromHeight( // MediaQuery.of(context).size.height * 0.070), // child: Container( // height: MediaQuery.of(context).size.height * 0.070, // decoration: BoxDecoration( // border: Border( // bottom: BorderSide( // color: Theme.of(context).dividerColor, // width: 0.5), //width: 0.7 // ), // color: Colors.white), // child: Center( // child: TabBar( // isScrollable: false, // controller: _tabController, // // indicatorColor: Colors.transparent, // indicatorWeight: 1.0, // indicatorSize: TabBarIndicatorSize.tab, // indicatorColor:Colors.green, // labelColor: Theme.of(context).primaryColor, // labelPadding: EdgeInsets.only( // top: 0, left: 0, right: 0, bottom: 0), // unselectedLabelColor: Colors.grey[800], // tabs: [ // tabWidget(screenSize, _activeTab == 0, // TranslationBase.of(context).details, // ), // tabWidget(screenSize, _activeTab == 1, // TranslationBase.of(context).review, // ), // tabWidget(screenSize, _activeTab == 2, // TranslationBase.of(context).availability), // ], // ), // ), // ), // ), // body: Column( // children: [ // Expanded( // child: TabBarView( // physics: BouncingScrollPhysics(), // controller: _tabController, // children: [ // DetailsInfo( // product: widget.product, // ), // ReviewsInfo( // product: widget.product, // ), // AvailabilityInfo() // ], // ), // ), // // ], // ), // ), // ), SizedBox( height: 6, ), //TODO Elham* Remove this Container( // width: 500, margin: EdgeInsets.only(bottom: 6), color: Colors.white, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Column( children: [ FlatButton( onPressed: () { setState(() { isDetails = true; isReviews = false; isAvailability = false; }); }, child: Text( TranslationBase.of(context).details, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold), ), color: Colors.white, ), CustomDivider( color: isDetails ? Colors.green : Colors.transparent, ) ], ), SizedBox( width: 20, ), Column( children: [ FlatButton( onPressed: () { setState(() { isDetails = false; isReviews = true; isAvailability = false; }); }, child: Text( TranslationBase.of(context).reviews, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold), ), color: Colors.white, ), CustomDivider( color: isReviews ? Colors.green : Colors.transparent, ), ], ), SizedBox( width: 20, ), Column( children: [ FlatButton( onPressed: () { setState(() { isDetails = false; isReviews = false; isAvailability = true; }); }, child: Text( TranslationBase.of(context).availability, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold), ), color: Colors.white, ), CustomDivider( color: isAvailability ? Colors.green : Colors.transparent, ), ], ), ], ), SizedBox( height: 10, ), isDetails ? DetailsInfo( product: widget.product, ) : isReviews ? ReviewsInfo( product: widget.product, ) : isAvailability ? AvailabilityInfo() : Container(), ], ), ), ///TODO Elham* check if we need recommanded // Row( // children: [ // customerId != null // ? Container( // width: 410, // height: 50, // color: Colors.white, // child: Texts( // TranslationBase.of(context).recommended, // bold: true, // ), // ) // : Container(), // ], // ), // RecommendedProducts(product: widget.product) SizedBox( height: 80, ) ], ), ), bottomSheet: FooterWidget( widget.product.stockAvailability != 'Out of stock', widget.product.orderMaximumQuantity, widget.product.orderMinimumQuantity, widget.product.stockQuantity, widget.product, price: price, isOverQuantity: isOverQuantity, addToCartFunction: addToCartFunction, ), ) : AppScaffold( appBarTitle: TranslationBase.of(context).productDetails, isShowAppBar: true, isPharmacy: true, isShowDecPage: false, showPharmacyCart: false, showHomeAppBarIcon: false, body: SingleChildScrollView( child: Column( children: [ Container( width: double.infinity, color: Colors.white, child: Column( children: [ Image.network( widget.product.images[0].src.trim(), ), widget.product.discountDescription != null ? Container( width: double.infinity, height: 50, color: Colors.yellowAccent, child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 1, child: Container( alignment: Alignment.centerRight, child: projectViewModel.isArabic ? Text( widget.product .discountDescriptionn, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 17), ) : Text( widget.product .discountDescription, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 17), ), ), ), SizedBox( width: 10, ), Expanded( flex: 0, child: Container( child: Image( image: AssetImage( 'assets/images/offer.png'), ), ), ), ], ), ) : Container(), ], ), ), SizedBox( height: 4, ), Container( width: 500, height: 150, color: Colors.white, child: ProductNameAndPrice( context, widget.product, customerId: customerId, addToWishlistFunction: addToWishlistFunction, deleteFromWishlistFunction: deleteFromWishlistFunction, notifyMeWhenAvailable: notifyMeWhenAvailable, isInWishList: isInWishList, ), ), SizedBox( height: 6, ), Container( width: 500, height: 120, color: Colors.white, child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.all(8.0), child: Container( child: Text( TranslationBase.of(context).specification, style: TextStyle(fontWeight: FontWeight.bold), ), ), ), Divider(color: Colors.grey) ], ), ), SizedBox( height: 6, ), Container( width: 500, margin: EdgeInsets.only(bottom: 100), // height: 350, color: Colors.white, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Column( children: [ FlatButton( onPressed: () { setState(() { isDetails = true; isReviews = false; isAvailability = false; }); }, child: Text( TranslationBase.of(context).details, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold), ), color: Colors.white, ), isDetails ? Container( width: 100, height: 5, color: Colors.green, ) : Container() ], ), SizedBox( width: 20, ), Column( children: [ FlatButton( onPressed: () { setState(() { isDetails = false; isReviews = true; isAvailability = false; }); }, child: Text( TranslationBase.of(context).reviews, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold), ), color: Colors.white, ), isReviews ? Container( width: 100, height: 5, color: Colors.green, ) : Container(), ], ), SizedBox( width: 20, ), Column( children: [ FlatButton( onPressed: () { setState(() { isDetails = false; isReviews = false; isAvailability = true; }); }, child: Text( TranslationBase.of(context).availability, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold), ), color: Colors.white, ), isAvailability ? Container( width: 100, height: 5, color: Colors.green, ) : Container(), ], ), ], ), SizedBox( height: 10, ), isDetails ? Padding( padding: const EdgeInsets.all(8.0), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( child: Text( TranslationBase.of(context).description, style: TextStyle( fontSize: 17, color: Colors.grey, fontWeight: FontWeight.w600), ), ), SizedBox( height: 6, ), Divider(height: 1, color: Colors.grey), SizedBox( height: 10, ), Container( child: Text( projectViewModel.isArabic ? widget.product.shortDescriptionn : widget.product.shortDescription, style: TextStyle( fontSize: 16, fontFamily: 'WorkSans-Regular'), ), ), SizedBox( height: 10, ), Container( child: Text( TranslationBase.of(context).howToUse, style: TextStyle( fontSize: 17, color: Colors.grey, fontWeight: FontWeight.w600), ), ), SizedBox( height: 6, ), Divider(height: 2, color: Colors.grey), SizedBox( height: 10, ), Container( child: Text( projectViewModel.isArabic ? widget.product.fullDescriptionn : widget.product.fullDescription, style: TextStyle( fontSize: 16, fontFamily: 'WorkSans-Regular'), ), ), ], ), ) : isReviews ? BaseView( onModelReady: (model) => model.getProductReviewsData( widget.product.id), builder: (_, model, wi) => model .productDetailService .length != 0 && model.productDetailService[0] .reviews.length != 0 ? ListView.builder( physics: ScrollPhysics(), itemCount: model .productDetailService[0] .reviews .length, scrollDirection: Axis.vertical, shrinkWrap: true, itemBuilder: (BuildContext context, int index) { return Padding( padding: EdgeInsets.all(8.0), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( child: Row( children: [ Container( child: Text( model .productDetailService[ 0] .reviews[ index] .customerId .toString(), style: TextStyle( fontSize: 17, color: Colors .grey, fontWeight: FontWeight .w600), ), ), Container( margin: EdgeInsets.only( left: 210), child: RatingBar .readOnly( initialRating: model .productDetailService[ 0] .reviews[ index] .rating .toDouble(), size: 15.0, filledColor: Colors.yellow[ 700], emptyColor: Colors .grey[500], isHalfAllowed: true, halfFilledIcon: Icons .star_half, filledIcon: Icons.star, emptyIcon: Icons.star, ), ), ], ), ), SizedBox( height: 10, ), Container( child: Text( model .productDetailService[ 0] .reviews[index] .reviewText, style: TextStyle( fontSize: 20), ), ), SizedBox( height: 50, ), Divider( height: 1, color: Colors.grey), ], ), ); }, ) : Container( padding: EdgeInsets.all(15), alignment: Alignment.center, child: Text( TranslationBase.of(context) .noReviewsAvailable), ), ) : isAvailability ? BaseView( onModelReady: (model) => model.getProductLocationData(), builder: (_, model, wi) => ListView.builder( physics: ScrollPhysics(), scrollDirection: Axis.vertical, shrinkWrap: true, itemCount: model .productLocationService.length, itemBuilder: (BuildContext context, int index) { return Padding( padding: EdgeInsets.all(8.0), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( flex: 1, child: Image.network(model .productLocationService[ index] .projectImageUrl), ), SizedBox( width: 10, ), Expanded( flex: 4, child: Text( model .productLocationService[ index] .locationDescription + "\n" + convertCityName( model .productLocationService[ 0] .cityName .toString(), ), style: TextStyle( fontSize: 12), ), ), Expanded( flex: 1, child: IconButton( icon: Icon(Icons .location_on), color: Colors.red, onPressed: () {}, ), ), Expanded( flex: 1, child: IconButton( icon: Icon(Icons.phone), color: Colors.red, onPressed: () {}, ), ), ], ), Divider( height: 1.2, color: Colors.grey) ], ), ); }, ), ) : Container(), ], ), ), ], ), ), bottomSheet: FooterWidget( widget.product.stockAvailability != 'Out of stock', widget.product.orderMaximumQuantity, widget.product.orderMinimumQuantity, widget.product.stockQuantity, widget.product, price: price, isOverQuantity: isOverQuantity, addToCartFunction: addToCartFunction, ), ); } } class CustomDivider extends StatelessWidget { const CustomDivider({ Key key, this.color, }) : super(key: key); final Color color; @override Widget build(BuildContext context) { return Container( width: 120, height: 2, color: color, ); } } convertCityName(txt) { String stringTxt; String newTxt; stringTxt = txt.toString(); newTxt = stringTxt.split('.')[1]; return newTxt; } addToCartFunction(quantity, itemID, BuildContext context) async { GifLoaderDialogUtils.showMyDialog(context); ProductDetailViewModel x = new ProductDetailViewModel(); await x.addToCartData(quantity, itemID).then((value) { GifLoaderDialogUtils.hideDialog(context); }); } notifyMeWhenAvailable(context, itemId) async { ProductDetailViewModel x = new ProductDetailViewModel(); await x.notifyMe(customerId, itemId); } addToWishlistFunction(itemID) async { ProductDetailViewModel x = new ProductDetailViewModel(); isInWishList = true; await x.addToWishlistData(itemID); } deleteFromWishlistFunction(itemID) async { ProductDetailViewModel x = new ProductDetailViewModel(); isInWishList = false; await x.deletWishlistData(itemID); } //TODO Elham* move to file Widget tabWidget( Size screenSize, bool isActive, String title, ) { return Center( child: Container( height: screenSize.height * 0.070, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ AppText( title, fontSize: SizeConfig.textMultiplier * 1.5, // color: Color(0xFF2B353E), fontWeight: FontWeight.w700, ), ], ), ), ); }