import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.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:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import 'package:rating_bar/rating_bar.dart'; class ProductNameAndPrice extends StatefulWidget { BuildContext context; PharmacyProduct item; final customerId; final bool isInWishList; final Function notifyMeWhenAvailable; final Function addToWishlistFunction; final Function deleteFromWishlistFunction; ProductNameAndPrice(this.context, this.item, {this.customerId, this.isInWishList, this.notifyMeWhenAvailable, this.addToWishlistFunction, this.deleteFromWishlistFunction}); @override _ProductNameAndPriceState createState() => _ProductNameAndPriceState(); } class _ProductNameAndPriceState extends State { @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); return Column( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox(height: 10,), FractionallySizedBox( widthFactor: 0.95, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Texts(widget.item.price.toString() + " " + "SAR", fontWeight: FontWeight.bold, fontSize: 20 ), Texts( projectViewModel.isArabic ? widget.item.stockAvailabilityn : widget.item.stockAvailability, fontWeight: FontWeight.bold, fontSize: 15, color: widget.item.stockAvailability == 'Out of stock'?Colors.red:Colors.green, ), // SizedBox(width: 20), widget.item.stockAvailability == 'Out of stock' && widget.customerId != null ? InkWell( onTap: () => widget.notifyMeWhenAvailable(context, widget.item.id), child: Row(children: [ Texts( TranslationBase.of(context).notifyMe, decoration: TextDecoration.underline, color: Colors.blue, ), SizedBox(width: 4), Icon( FontAwesomeIcons.bell, color: Colors.blue, size: 15.0, ) ]), ) : Container( margin: projectViewModel.isArabic ? EdgeInsets.only(right: 25) : EdgeInsets.only(left: 25), width: 40, height: 40, decoration: BoxDecoration( color: Colors.grey[300], borderRadius: BorderRadius.circular(30), ), child: IconButton( icon: Icon(!widget.isInWishList ? Icons.favorite_border : Icons.favorite), color: !widget.isInWishList ? Colors.white : Colors.red, onPressed: () async { if (widget.customerId != null) { if (!widget.isInWishList) { GifLoaderDialogUtils.showMyDialog(context); await widget .addToWishlistFunction(widget.item.id); GifLoaderDialogUtils.hideDialog(context); } else { await widget .deleteFromWishlistFunction(widget.item.id); } } else { return; } setState(() {}); }, )), ], ), ), Padding( padding: const EdgeInsets.all(8.0), child: Container( margin: EdgeInsets.only(left: 5), child: Align( alignment: projectViewModel.isArabic ? Alignment.topRight : Alignment.topLeft, child: Text( projectViewModel.isArabic ? widget.item.namen : widget.item.name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15), ), ), ), ), FractionallySizedBox( widthFactor: 0.95, child: Row( children: [ Container( child: Align( alignment: Alignment.bottomLeft, child: Row( children: [ RatingBar.readOnly( initialRating:double.parse( widget.item.approvedRatingSum.toString()), size: 15.0, filledColor: Colors.yellow[700], emptyColor: Colors.grey[400], isHalfAllowed: true, halfFilledIcon: Icons.star_half, filledIcon: Icons.star, emptyIcon: Icons.star, ), SizedBox(width: 10,), Texts( "${widget.item.approvedRatingSum}", fontWeight: FontWeight.bold, fontSize: 12, ), SizedBox(width: 30,), Texts( "(${widget.item.approvedTotalReviews}${TranslationBase.of(context).review})", fontSize: 12, ), ], ), ), ), Expanded( flex: 1, child: Container( child: widget.item.rxMessage != null ? Text( projectViewModel.isArabic ? widget.item.rxMessagen.toString() : widget.item.rxMessage.toString(), style: TextStyle(color: Colors.red, fontSize: 10), ) : Container()), ), widget.item.rxMessage != null ? Icon( FontAwesomeIcons.questionCircle, color: Colors.red, size: 15.0, ) : Container(), ], ), ), SizedBox(height: 10,), ], ); } }