You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App/lib/widgets/offers_packages/PackagesCartItemCard.dart

137 lines
5.1 KiB
Dart

import 'package:diplomaticquarterapp/core/model/packages_offers/responses/PackagesCartItemsResponseModel.dart';
import 'package:diplomaticquarterapp/core/model/packages_offers/responses/PackagesResponseModel.dart';
import 'package:diplomaticquarterapp/core/viewModels/packages_offers/PackagesOffersViewModel.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/CounterView.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
bool wide = true;
class PackagesCartItemCard extends StatefulWidget {
final PackagesCartItemsResponseModel itemModel;
final StepperCallbackFuture shouldStepperChangeApply;
final PackagesViewModel viewModel;
final Function getCartItems;
const PackagesCartItemCard({@required this.itemModel, @required this.shouldStepperChangeApply, @required this.viewModel, this.getCartItems, Key key}) : super(key: key);
@override
State<StatefulWidget> createState() => PackagesCartItemCardState();
}
class PackagesCartItemCardState extends State<PackagesCartItemCard> {
@override
Widget build(BuildContext context) {
wide = !wide;
return Container(
decoration: cardRadius(15.0),
margin: EdgeInsets.only(left: 21.0, right: 21.0, top: 12.0),
height: 90,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
_image(widget.itemModel.product),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_itemName(widget.itemModel.product.getName()),
_itemDescription(widget.itemModel.product.shortDescription),
Container(
padding: const EdgeInsets.only(top: 12.0),
width: MediaQuery.of(context).size.width * 0.65,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_itemPrice(widget.itemModel.product.price, context: context),
InkWell(
onTap: () async {
await widget.viewModel.service.deleteProductFromCart(widget.itemModel.id, context: context, showLoading: false);
widget.getCartItems();
},
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 5.0, right: 5.0),
child: Text(
TranslationBase.of(context).removeMember,
style: TextStyle(
fontSize: 10,
color: CustomColors.accentColor,
fontWeight: FontWeight.w600,
letterSpacing: -0.36,
),
),
),
SvgPicture.asset("assets/images/new-design/delete.svg", color: CustomColors.accentColor),
],
),
),
],
),
),
],
)
],
),
);
}
}
Widget _image(PackagesResponseModel model) => AspectRatio(
aspectRatio: 1 / 1,
child: Padding(
padding: const EdgeInsets.all(9),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[300], width: 0.25),
boxShadow: [BoxShadow(color: Colors.grey[200], blurRadius: 2.0, spreadRadius: 1, offset: Offset(1, 1.5))],
borderRadius: BorderRadius.circular(15),
color: Colors.white,
shape: BoxShape.rectangle,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: (model.images.isNotEmpty) ? Utils.loadNetworkImage(url: model.images.first.src, fitting: BoxFit.fill) : Container(color: Colors.grey[200])),
),
),
);
Widget _itemName(String name) => Padding(
padding: const EdgeInsets.only(top: 9.0),
child: Text(name,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
letterSpacing: -0.56,
)));
Widget _itemDescription(String desc) => Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Text(desc,
style: TextStyle(
fontSize: 10,
// fontWeight: FontWeight.bold,
letterSpacing: -0.4,
)));
Widget _itemPrice(double price, {@required BuildContext context}) {
final prc = (price ?? 0.0).toStringAsFixed(2);
return Padding(
padding: const EdgeInsets.all(0),
child: Text(
'${prc} ${TranslationBase.of(context).sar}',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
letterSpacing: -0.4,
),
),
);
}