|
|
|
@ -45,7 +45,8 @@ class PackagesCartPage extends StatefulWidget {
|
|
|
|
|
_PackagesCartPageState createState() => _PackagesCartPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMixin<PackagesCartPage>, SingleTickerProviderStateMixin {
|
|
|
|
|
class _PackagesCartPageState extends State<PackagesCartPage>
|
|
|
|
|
with AfterLayoutMixin<PackagesCartPage>, SingleTickerProviderStateMixin {
|
|
|
|
|
getLanguageID() async {
|
|
|
|
|
languageID = await sharedPref.getString(APP_LANGUAGE);
|
|
|
|
|
}
|
|
|
|
@ -54,7 +55,8 @@ class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMix
|
|
|
|
|
void initState() {
|
|
|
|
|
_agreeTerms = false;
|
|
|
|
|
_selectedPaymentMethod = null;
|
|
|
|
|
_animationController = AnimationController(vsync: this, duration: Duration(seconds: 500));
|
|
|
|
|
_animationController =
|
|
|
|
|
AnimationController(vsync: this, duration: Duration(seconds: 500));
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -77,20 +79,25 @@ class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMix
|
|
|
|
|
Navigator.push(context, FadePage(page: PharmacyTermsConditions()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onPayNowClick() async{
|
|
|
|
|
await viewModel.service.placeOrder(context: context,paymentOption: _selectedPaymentMethod.toUpperCase()).then((orderId){
|
|
|
|
|
if(orderId.runtimeType == int){ // result == order_id
|
|
|
|
|
onPayNowClick() async {
|
|
|
|
|
await viewModel.service
|
|
|
|
|
.placeOrder(
|
|
|
|
|
context: context,
|
|
|
|
|
paymentOption: _selectedPaymentMethod.toUpperCase())
|
|
|
|
|
.then((orderId) {
|
|
|
|
|
if (orderId.runtimeType == int) {
|
|
|
|
|
// result == order_id
|
|
|
|
|
var browser = MyInAppBrowser(
|
|
|
|
|
context: context,
|
|
|
|
|
onExitCallback: (data, isDone) => paymentClosed(orderId: orderId, withStatus: isDone, data: data)
|
|
|
|
|
);
|
|
|
|
|
browser.openPackagesPaymentBrowser(customer_id: viewModel.service.customer.id, order_id: orderId);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
utils.Utils.showErrorToast('Failed to place order, please try again later');
|
|
|
|
|
onExitCallback: (data, isDone) => paymentClosed(
|
|
|
|
|
orderId: orderId, withStatus: isDone, data: data));
|
|
|
|
|
browser.openPackagesPaymentBrowser(
|
|
|
|
|
customer_id: viewModel.service.customer.id, order_id: orderId);
|
|
|
|
|
} else {
|
|
|
|
|
utils.Utils.showErrorToast(
|
|
|
|
|
'Failed to place order, please try again later');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).catchError((error){
|
|
|
|
|
}).catchError((error) {
|
|
|
|
|
utils.Utils.showErrorToast(error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -124,7 +131,6 @@ class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMix
|
|
|
|
|
crossAxisCount: (_columnCount * _columnCount),
|
|
|
|
|
itemCount: viewModel.cartItemList.length,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
|
|
|
|
|
var item = viewModel.cartItemList[index];
|
|
|
|
|
return Dismissible(
|
|
|
|
|
key: Key(index.toString()),
|
|
|
|
@ -132,7 +138,9 @@ class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMix
|
|
|
|
|
background: _cartItemDeleteContainer(),
|
|
|
|
|
secondaryBackground: _cartItemDeleteContainer(),
|
|
|
|
|
confirmDismiss: (direction) async {
|
|
|
|
|
bool status = await viewModel.service.deleteProductFromCart(item.id, context: context, showLoading: false);
|
|
|
|
|
bool status = await viewModel.service
|
|
|
|
|
.deleteProductFromCart(item.id,
|
|
|
|
|
context: context, showLoading: false);
|
|
|
|
|
return status;
|
|
|
|
|
},
|
|
|
|
|
onDismissed: (direction) {
|
|
|
|
@ -141,17 +149,23 @@ class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMix
|
|
|
|
|
},
|
|
|
|
|
child: PackagesCartItemCard(
|
|
|
|
|
itemModel: item,
|
|
|
|
|
shouldStepperChangeApply: (apply,total) async{
|
|
|
|
|
var request = AddProductToCartRequestModel(product_id: item.productId, quantity: apply);
|
|
|
|
|
ResponseModel response = await viewModel.service.addProductToCart(request, context: context, showLoading: false).catchError((error){
|
|
|
|
|
shouldStepperChangeApply: (apply, total) async {
|
|
|
|
|
var request = AddProductToCartRequestModel(
|
|
|
|
|
product_id: item.productId,
|
|
|
|
|
quantity: apply);
|
|
|
|
|
ResponseModel response = await viewModel
|
|
|
|
|
.service
|
|
|
|
|
.addProductToCart(request,
|
|
|
|
|
context: context, showLoading: false)
|
|
|
|
|
.catchError((error) {
|
|
|
|
|
utils.Utils.showErrorToast(error);
|
|
|
|
|
});
|
|
|
|
|
return response.status ?? false;
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
));
|
|
|
|
|
},
|
|
|
|
|
staggeredTileBuilder: (int index) => StaggeredTile.fit(_columnCount),
|
|
|
|
|
staggeredTileBuilder: (int index) =>
|
|
|
|
|
StaggeredTile.fit(_columnCount),
|
|
|
|
|
mainAxisSpacing: 0,
|
|
|
|
|
crossAxisSpacing: 10,
|
|
|
|
|
)),
|
|
|
|
@ -164,25 +178,29 @@ class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMix
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Texts(
|
|
|
|
|
TranslationBase.of(context).selectPaymentOption,
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
|
Texts(TranslationBase.of(context).selectPaymentOption,
|
|
|
|
|
fontSize: 10, fontWeight: FontWeight.bold),
|
|
|
|
|
Container(
|
|
|
|
|
height: 0.25,
|
|
|
|
|
width: 100,
|
|
|
|
|
color: Colors.grey[300],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Container(height: 0.25, width: 100, color: Colors.grey[300],),
|
|
|
|
|
|
|
|
|
|
_paymentOptions(context, (paymentMethod) {
|
|
|
|
|
setState(() => _selectedPaymentMethod = paymentMethod);
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
Container(height: 0.25, color: Colors.grey[300],),
|
|
|
|
|
|
|
|
|
|
Container(height: 40,
|
|
|
|
|
child: _termsAndCondition(context, onSelected: onTermsClick, onInfoClick: onTermsInfoClick)
|
|
|
|
|
Container(
|
|
|
|
|
height: 0.25,
|
|
|
|
|
color: Colors.grey[300],
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
height: 40,
|
|
|
|
|
child: _termsAndCondition(context,
|
|
|
|
|
onSelected: onTermsClick,
|
|
|
|
|
onInfoClick: onTermsInfoClick)),
|
|
|
|
|
Container(
|
|
|
|
|
height: 0.25,
|
|
|
|
|
color: Colors.grey[300],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Container(height: 0.25, color: Colors.grey[300],),
|
|
|
|
|
_payNow(context, onPayNowClick: onPayNowClick)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
@ -195,19 +213,19 @@ class _PackagesCartPageState extends State<PackagesCartPage> with AfterLayoutMix
|
|
|
|
|
|
|
|
|
|
fetchData() async {
|
|
|
|
|
await viewModel.service.cartItems(context: context).catchError((error) {});
|
|
|
|
|
setState((){});
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paymentClosed({@required int orderId, @required bool withStatus, dynamic data}) async{
|
|
|
|
|
viewModel.service.getOrderById(orderId, context: context).then((value){
|
|
|
|
|
paymentClosed(
|
|
|
|
|
{@required int orderId, @required bool withStatus, dynamic data}) async {
|
|
|
|
|
viewModel.service.getOrderById(orderId, context: context).then((value) {
|
|
|
|
|
var heading = withStatus ? "Success" : "Failed";
|
|
|
|
|
var title = "Your order has been placed successfully";
|
|
|
|
|
var subTitle = "Order# ${value.data.customOrderNumber}";
|
|
|
|
|
Navigator.of(context).pushReplacement(
|
|
|
|
|
MaterialPageRoute(builder: (context) => PackageOrderCompletedPage(heading: heading, title: title, subTitle: subTitle))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}).catchError((error){
|
|
|
|
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
|
|
|
|
builder: (context) => PackageOrderCompletedPage(
|
|
|
|
|
heading: heading, title: title, subTitle: subTitle)));
|
|
|
|
|
}).catchError((error) {
|
|
|
|
|
debugPrint(error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -231,13 +249,13 @@ Widget _paymentOptions(BuildContext context, Function(String) onSelected) {
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5)),
|
|
|
|
|
border: Border.all(color: isSelected ? Colors.green : Colors.grey, width: isSelected ? 1 : 0.5)
|
|
|
|
|
),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: isSelected ? Colors.green : Colors.grey,
|
|
|
|
|
width: isSelected ? 1 : 0.5)),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
|
child: Image.asset('assets/images/new-design/$imageName'),
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
@ -267,7 +285,8 @@ Widget _paymentOptions(BuildContext context, Function(String) onSelected) {
|
|
|
|
|
width: 5,
|
|
|
|
|
),
|
|
|
|
|
InkWell(
|
|
|
|
|
child: buttonContent(_selectedPaymentMethod == "mastercard", 'mastercard.png'),
|
|
|
|
|
child: buttonContent(
|
|
|
|
|
_selectedPaymentMethod == "mastercard", 'mastercard.png'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
onSelected("mastercard");
|
|
|
|
|
},
|
|
|
|
@ -276,7 +295,8 @@ Widget _paymentOptions(BuildContext context, Function(String) onSelected) {
|
|
|
|
|
width: 5,
|
|
|
|
|
),
|
|
|
|
|
InkWell(
|
|
|
|
|
child: buttonContent(_selectedPaymentMethod == "installment", 'installment.png'),
|
|
|
|
|
child: buttonContent(
|
|
|
|
|
_selectedPaymentMethod == "installment", 'installment.png'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
onSelected("installment");
|
|
|
|
|
},
|
|
|
|
@ -288,14 +308,17 @@ Widget _paymentOptions(BuildContext context, Function(String) onSelected) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _agreeTerms = false;
|
|
|
|
|
Widget _termsAndCondition(BuildContext context, {@required Function(bool) onSelected, @required VoidCallback onInfoClick}) {
|
|
|
|
|
Widget _termsAndCondition(BuildContext context,
|
|
|
|
|
{@required Function(bool) onSelected, @required VoidCallback onInfoClick}) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.all(5),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
InkWell(
|
|
|
|
|
child: Icon(
|
|
|
|
|
_agreeTerms ? Icons.check_circle : Icons.radio_button_unchecked_sharp,
|
|
|
|
|
_agreeTerms
|
|
|
|
|
? Icons.check_circle
|
|
|
|
|
: Icons.radio_button_unchecked_sharp,
|
|
|
|
|
size: 20,
|
|
|
|
|
color: _agreeTerms ? Colors.green[600] : Colors.grey[400],
|
|
|
|
|
),
|
|
|
|
@ -308,7 +331,8 @@ Widget _termsAndCondition(BuildContext context, {@required Function(bool) onSele
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
|
child: Texts(
|
|
|
|
|
TranslationBase.of(context).pharmacyServiceTermsCondition,
|
|
|
|
|
fontWeight: FontWeight.normal, fontSize: 13,
|
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
InkWell(
|
|
|
|
@ -340,9 +364,18 @@ Widget _payNow(BuildContext context, {@required VoidCallback onPayNowClick}) {
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Texts('${TranslationBase.of(context).subtotal}: ${'999.9'} ${TranslationBase.of(context).sar}',
|
|
|
|
|
heightFactor: 1.5, fontWeight: FontWeight.bold, color: Colors.grey, fontSize: 8),
|
|
|
|
|
Texts('${TranslationBase.of(context).vat}: ${'14.9'} ${TranslationBase.of(context).sar}', heightFactor: 1.5, fontWeight: FontWeight.bold, color: Colors.grey, fontSize: 8),
|
|
|
|
|
Texts(
|
|
|
|
|
'${TranslationBase.of(context).subtotal}: ${'999.9'} ${TranslationBase.of(context).sar}',
|
|
|
|
|
heightFactor: 1.5,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 8),
|
|
|
|
|
Texts(
|
|
|
|
|
'${TranslationBase.of(context).vat}: ${'14.9'} ${TranslationBase.of(context).sar}',
|
|
|
|
|
heightFactor: 1.5,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 8),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(3),
|
|
|
|
|
child: Container(
|
|
|
|
@ -351,8 +384,12 @@ Widget _payNow(BuildContext context, {@required VoidCallback onPayNowClick}) {
|
|
|
|
|
color: Colors.grey[300],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Texts('${TranslationBase.of(context).total}: 999.99 ${TranslationBase.of(context).sar}',
|
|
|
|
|
heightFactor: 1.5, fontWeight: FontWeight.bold, color: Colors.black54, fontSize: 15)
|
|
|
|
|
Texts(
|
|
|
|
|
'${TranslationBase.of(context).total}: 999.99 ${TranslationBase.of(context).sar}',
|
|
|
|
|
heightFactor: 1.5,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.black54,
|
|
|
|
|
fontSize: 15)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
@ -360,10 +397,15 @@ Widget _payNow(BuildContext context, {@required VoidCallback onPayNowClick}) {
|
|
|
|
|
RaisedButton(
|
|
|
|
|
child: Texts(
|
|
|
|
|
TranslationBase.of(context).payNow,
|
|
|
|
|
fontSize: 15, color: Colors.white, fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
padding: EdgeInsets.only(top: 5, bottom: 5, left: 0, right: 0),
|
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5), side: BorderSide(color: Theme.of(context).primaryColor, width: 0.5)),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
|
side: BorderSide(
|
|
|
|
|
color: Theme.of(context).primaryColor, width: 0.5)),
|
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
|
onPressed: isPayNowAQctive ? onPayNowClick : null,
|
|
|
|
|
),
|
|
|
|
@ -381,23 +423,23 @@ Widget _cartItemDeleteContainer() {
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(5),
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.grey[500],
|
|
|
|
|
blurRadius: 2,
|
|
|
|
|
spreadRadius: 1,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5)),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.grey[500],
|
|
|
|
|
blurRadius: 2,
|
|
|
|
|
spreadRadius: 1,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5)),
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Texts(
|
|
|
|
|
"Deleting...",
|
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|