|
|
|
|
@ -1,15 +1,12 @@
|
|
|
|
|
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/pharmacies/screens/pharmacy-terms-conditions-page.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductOrderItem.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/navigation_service.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/buttons/GestureIconButton.dart';
|
|
|
|
|
@ -18,12 +15,8 @@ import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../../locator.dart';
|
|
|
|
|
import 'cart-order-preview.dart';
|
|
|
|
|
|
|
|
|
|
class CartOrderPage extends StatefulWidget {
|
|
|
|
|
final Function(int) changeTab;
|
|
|
|
|
|
|
|
|
|
@ -64,8 +57,7 @@ class _CartOrderPageState extends State<CartOrderPage> {
|
|
|
|
|
body: NetworkBaseView(
|
|
|
|
|
isLoading: isLoading,
|
|
|
|
|
isLocalLoader: true,
|
|
|
|
|
child: !(model.cartResponse.shoppingCarts == null ||
|
|
|
|
|
model.cartResponse.shoppingCarts.length == 0)
|
|
|
|
|
child: !(model.cartResponse.shoppingCarts == null || model.cartResponse.shoppingCarts.length == 0)
|
|
|
|
|
? Container(
|
|
|
|
|
height: height * 0.85,
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
@ -92,19 +84,17 @@ class _CartOrderPageState extends State<CartOrderPage> {
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
itemCount:
|
|
|
|
|
model.cartResponse.shoppingCarts.length,
|
|
|
|
|
itemCount: model.cartResponse.shoppingCarts.length,
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
physics: ScrollPhysics(),
|
|
|
|
|
// physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
|
// physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
return ProductOrderItem(
|
|
|
|
|
item: model.cartResponse.shoppingCarts[index],
|
|
|
|
|
changeCartItems: () async {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
await model.changeProductQuantity(model
|
|
|
|
|
.cartResponse.shoppingCarts[index]);
|
|
|
|
|
await model.changeProductQuantity(model.cartResponse.shoppingCarts[index]);
|
|
|
|
|
if (model.state != ViewState.Error) {}
|
|
|
|
|
if (model.state == ViewState.ErrorLocal) {
|
|
|
|
|
Utils.showErrorToast(model.error);
|
|
|
|
|
@ -113,10 +103,7 @@ class _CartOrderPageState extends State<CartOrderPage> {
|
|
|
|
|
},
|
|
|
|
|
deleteCartItems: () async {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
await model
|
|
|
|
|
.deleteProduct(model
|
|
|
|
|
.cartResponse.shoppingCarts[index])
|
|
|
|
|
.then((value) {
|
|
|
|
|
await model.deleteProduct(model.cartResponse.shoppingCarts[index]).then((value) {
|
|
|
|
|
if (model.state == ViewState.ErrorLocal) {
|
|
|
|
|
Utils.showErrorToast(model.error);
|
|
|
|
|
}
|
|
|
|
|
@ -246,10 +233,7 @@ class _CartOrderPageState extends State<CartOrderPage> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
bottomSheet: Container(
|
|
|
|
|
height: !(model.cartResponse.shoppingCarts == null ||
|
|
|
|
|
model.cartResponse.shoppingCarts.length == 0)
|
|
|
|
|
? height * 0.15
|
|
|
|
|
: 0,
|
|
|
|
|
height: !(model.cartResponse.shoppingCarts == null || model.cartResponse.shoppingCarts.length == 0) ? height * 0.15 : 0,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
child: OrderBottomWidget(model.addresses, height, model, isLoading),
|
|
|
|
|
),
|
|
|
|
|
@ -257,8 +241,7 @@ class _CartOrderPageState extends State<CartOrderPage> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getData() async {
|
|
|
|
|
await Provider.of<OrderPreviewViewModel>(context, listen: false)
|
|
|
|
|
.getShoppingCart();
|
|
|
|
|
await Provider.of<OrderPreviewViewModel>(context, listen: false).getShoppingCart();
|
|
|
|
|
setState(() {
|
|
|
|
|
isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
@ -284,9 +267,7 @@ class _OrderBottomWidgetState extends State<OrderBottomWidget> {
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
ProjectViewModel projectProvider = Provider.of(context);
|
|
|
|
|
|
|
|
|
|
return !widget.isLoading &&
|
|
|
|
|
!(widget.model.cartResponse.shoppingCarts == null ||
|
|
|
|
|
widget.model.cartResponse.shoppingCarts.length == 0)
|
|
|
|
|
return !widget.isLoading && !(widget.model.cartResponse.shoppingCarts == null || widget.model.cartResponse.shoppingCarts.length == 0)
|
|
|
|
|
? Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
@ -333,8 +314,7 @@ class _OrderBottomWidgetState extends State<OrderBottomWidget> {
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 4),
|
|
|
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
|
|
|
child: Texts(
|
|
|
|
|
TranslationBase.of(context)
|
|
|
|
|
.pharmacyServiceTermsCondition,
|
|
|
|
|
TranslationBase.of(context).pharmacyServiceTermsCondition,
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
color: Colors.grey.shade800,
|
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
|
@ -342,10 +322,7 @@ class _OrderBottomWidgetState extends State<OrderBottomWidget> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () => {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context, FadePage(page: PharmacyTermsConditions()))
|
|
|
|
|
},
|
|
|
|
|
onTap: () => {Navigator.push(context, FadePage(page: PharmacyTermsConditions()))},
|
|
|
|
|
child: Container(
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.info,
|
|
|
|
|
@ -371,8 +348,7 @@ class _OrderBottomWidgetState extends State<OrderBottomWidget> {
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 0, vertical: 0),
|
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Texts(
|
|
|
|
|
@ -381,8 +357,7 @@ class _OrderBottomWidgetState extends State<OrderBottomWidget> {
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 4),
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
|
|
|
child: Texts(
|
|
|
|
|
"${TranslationBase.of(context).inclusiveVat}",
|
|
|
|
|
fontSize: 8,
|
|
|
|
|
@ -404,33 +379,16 @@ class _OrderBottomWidgetState extends State<OrderBottomWidget> {
|
|
|
|
|
),
|
|
|
|
|
RaisedButton(
|
|
|
|
|
onPressed: isAgree
|
|
|
|
|
// && cart.cartResponse.shoppingCarts[1].product.stockQuantity ==0
|
|
|
|
|
? () => {
|
|
|
|
|
if (widget.model.isCartItemsOutOfStock())
|
|
|
|
|
{
|
|
|
|
|
// Toast msg
|
|
|
|
|
AppToast.showErrorToast(
|
|
|
|
|
message: TranslationBase.of(context)
|
|
|
|
|
.outOfStockMsg)
|
|
|
|
|
}
|
|
|
|
|
{AppToast.showErrorToast(message: TranslationBase.of(context).outOfStockMsg)}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_navigateToAddressPage(widget
|
|
|
|
|
.model.user.patientIdentificationNo)
|
|
|
|
|
// Navigator.push(
|
|
|
|
|
// context,
|
|
|
|
|
// FadePage(
|
|
|
|
|
// page:
|
|
|
|
|
// OrderPreviewPage(widget.addresses)))
|
|
|
|
|
}
|
|
|
|
|
{_navigateToAddressPage(widget.model.user.patientIdentificationNo)}
|
|
|
|
|
}
|
|
|
|
|
: null,
|
|
|
|
|
child: new Text(
|
|
|
|
|
"${TranslationBase.of(context).checkOut}",
|
|
|
|
|
style: new TextStyle(
|
|
|
|
|
color:
|
|
|
|
|
isAgree ? Colors.white : Colors.grey.shade300,
|
|
|
|
|
fontSize: 14),
|
|
|
|
|
style: new TextStyle(color: isAgree ? Colors.white : Colors.grey.shade300, fontSize: 14),
|
|
|
|
|
),
|
|
|
|
|
color: Color(0xFF4CAF50),
|
|
|
|
|
disabledColor: Color(0xFF848484),
|
|
|
|
|
@ -454,8 +412,7 @@ class _OrderBottomWidgetState extends State<OrderBottomWidget> {
|
|
|
|
|
if (result != null) {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
var address = result;
|
|
|
|
|
widget.model.paymentCheckoutData.address =
|
|
|
|
|
Addresses.fromJson(address.toJson());
|
|
|
|
|
widget.model.paymentCheckoutData.address = Addresses.fromJson(address.toJson());
|
|
|
|
|
await widget.model.getInformationsByAddress(identificationNo);
|
|
|
|
|
await widget.model.getShoppingCart();
|
|
|
|
|
// widget.changeMainState();
|
|
|
|
|
|