diff --git a/lib/core/service/pharmacy_categorise_service.dart b/lib/core/service/pharmacy_categorise_service.dart index 3cc45680..be376c91 100644 --- a/lib/core/service/pharmacy_categorise_service.dart +++ b/lib/core/service/pharmacy_categorise_service.dart @@ -187,11 +187,14 @@ class PharmacyCategoriseService extends BaseService { ); } - Future getSubProducts({String id}) async { + Future getSubProducts( + {String id, int pageIndex, bool isLoading = false}) async { hasError = false; - _subProductsList.clear(); + if (isLoading == false) { + _subProductsList.clear(); + } String endPoint = id != null - ? GET_SUB_PRODUCTS + "$id" + '&page=1&limit=50' + ? GET_SUB_PRODUCTS + "$id" + '&page=' + '$pageIndex' + '&limit=24' : GET_SUB_PRODUCTS + ""; await baseAppClient.getPharmacy( endPoint, diff --git a/lib/core/viewModels/pharmacy_categorise_view_model.dart b/lib/core/viewModels/pharmacy_categorise_view_model.dart index fcae18d2..2be2f14c 100644 --- a/lib/core/viewModels/pharmacy_categorise_view_model.dart +++ b/lib/core/viewModels/pharmacy_categorise_view_model.dart @@ -121,7 +121,7 @@ class PharmacyCategoriseViewModel extends BaseViewModel { hasError = false; // _insuranceCardService.clearInsuranceCard(); setState(ViewState.BusyLocal); - //GifLoaderDialogUtils.showMyDialog(context); + GifLoaderDialogUtils.showMyDialog(context); await _pharmacyCategoriseService.getParentProducts( id: i, pageNumber: pageIndex, isLoading: isLoading); if (_pharmacyCategoriseService.hasError) { @@ -129,31 +129,45 @@ class PharmacyCategoriseViewModel extends BaseViewModel { setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); - //GifLoaderDialogUtils.hideDialog(context); + GifLoaderDialogUtils.hideDialog(context); } - Future getSubCategorise({String i}) async { + Future getSubCategorise( + {String i, + int pageIndex, + bool isLoading = false, + BuildContext context}) async { hasError = false; // _insuranceCardService.clearInsuranceCard(); setState(ViewState.Busy); - await _pharmacyCategoriseService.getSubCategorise(id: i); + await _pharmacyCategoriseService.getSubCategorise( + id: i, + ); if (_pharmacyCategoriseService.hasError) { error = _pharmacyCategoriseService.error; setState(ViewState.ErrorLocal); } else - getSubProducts(i: i); + getSubProducts( + i: i, pageIndex: pageIndex, isLoading: isLoading, context: context); } - Future getSubProducts({String i}) async { + Future getSubProducts( + {String i, + int pageIndex, + bool isLoading = false, + BuildContext context}) async { hasError = false; // _insuranceCardService.clearInsuranceCard(); - setState(ViewState.Busy); - await _pharmacyCategoriseService.getSubProducts(id: i); + setState(ViewState.BusyLocal); + GifLoaderDialogUtils.showMyDialog(context); + await _pharmacyCategoriseService.getSubProducts( + id: i, pageIndex: pageIndex, isLoading: isLoading); if (_pharmacyCategoriseService.hasError) { error = _pharmacyCategoriseService.error; setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); + GifLoaderDialogUtils.hideDialog(context); } Future getFinalProducts({String i}) async { diff --git a/lib/pages/parent_categorise_page.dart b/lib/pages/parent_categorise_page.dart index 461e837c..5a917897 100644 --- a/lib/pages/parent_categorise_page.dart +++ b/lib/pages/parent_categorise_page.dart @@ -689,150 +689,159 @@ class _ParentCategorisePageState extends State { ), model.parentProducts.isNotEmpty ? styleOne == true - ? model.state != ViewState.BusyLocal - ? Container( - height: - model.parentProducts.length * - MediaQuery.of(context) - .size - .height * - 0.15, - child: GridView.builder( - physics: - NeverScrollableScrollPhysics(), - gridDelegate: - SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - crossAxisSpacing: 0.5, - mainAxisSpacing: 2.0, - childAspectRatio: 0.9, - ), - itemCount: - model.parentProducts.length, - itemBuilder: - (BuildContext context, - int index) { - return NetworkBaseView( - baseViewModel: model, - child: InkWell( - child: Card( - color: model - .parentProducts[ - index] - .discountName != - null - ? Color( - 0xffFFFF00) - : Colors.white, - elevation: 0, - shape: Border( - right: BorderSide( - color: Colors.grey - .shade300, - width: 1, - ), - left: BorderSide( - color: Colors.grey - .shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey - .shade300, - width: 1, - ), - top: BorderSide( - color: Colors.grey - .shade300, - width: 1, - ), - ), - margin: EdgeInsets - .symmetric( - horizontal: 8, - vertical: 4, + ? Container( + height: model.parentProducts.length * + MediaQuery.of(context) + .size + .height * + 0.15, + child: GridView.builder( + physics: + NeverScrollableScrollPhysics(), + gridDelegate: + SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + crossAxisSpacing: 0.5, + mainAxisSpacing: 2.0, + childAspectRatio: 0.9, + ), + itemCount: + model.parentProducts.length, + itemBuilder: (BuildContext context, + int index) { + return NetworkBaseView( + baseViewModel: model, + child: InkWell( + child: Card( + color: model + .parentProducts[ + index] + .discountName != + null + ? Color(0xffFFFF00) + : Colors.white, + elevation: 0, + shape: Border( + right: BorderSide( + color: Colors + .grey.shade300, + width: 1, + ), + left: BorderSide( + color: Colors + .grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors + .grey.shade300, + width: 1, + ), + top: BorderSide( + color: Colors + .grey.shade300, + width: 1, + ), + ), + margin: + EdgeInsets.symmetric( + horizontal: 8, + vertical: 4, + ), + child: Container( + decoration: + BoxDecoration( + borderRadius: + BorderRadius.only( + topLeft: + Radius.circular( + 110.0), ), - child: Container( - decoration: - BoxDecoration( - borderRadius: - BorderRadius - .only( - topLeft: Radius - .circular( - 110.0), - ), - color: - Colors.white, - ), - padding: EdgeInsets - .symmetric( - horizontal: - 0), - width: MediaQuery.of( - context) - .size - .width / - 3, - child: Column( - crossAxisAlignment: - CrossAxisAlignment - .start, + color: Colors.white, + ), + padding: EdgeInsets + .symmetric( + horizontal: 0), + width: MediaQuery.of( + context) + .size + .width / + 3, + child: Column( + crossAxisAlignment: + CrossAxisAlignment + .start, + children: [ + Stack( children: [ - Stack( - children: [ - if (model - .parentProducts[index] - .discountName != - null) - RotatedBox( - quarterTurns: - 4, + if (model + .parentProducts[ + index] + .discountName != + null) + RotatedBox( + quarterTurns: + 4, + child: + Container( + decoration: + BoxDecoration(), + child: + Padding( + padding: + EdgeInsets.only( + right: + 5.0, + top: + 20.0, + bottom: + 5.0, + ), child: - Container( - decoration: - BoxDecoration(), - child: - Padding( - padding: - EdgeInsets.only( - right: 5.0, - top: 20.0, - bottom: 5.0, - ), - child: - Texts( - TranslationBase.of(context).offers.toUpperCase(), - color: Colors.red, - fontSize: 13.0, - fontWeight: FontWeight.w900, - ), - ), - transform: - new Matrix4.rotationZ(5.837200), + Texts( + TranslationBase.of(context) + .offers + .toUpperCase(), + color: + Colors.red, + fontSize: + 13.0, + fontWeight: + FontWeight.w900, ), ), - Container( - margin: EdgeInsets - .fromLTRB( - 0, - 16, - 0, - 0), - alignment: - Alignment - .center, - child: Image - .network( - model.parentProducts[index].images.isNotEmpty - ? model.parentProducts[index].images[0].thumb - : 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/No_image_3x4.svg/1200px-No_image_3x4.svg.png', - fit: BoxFit - .cover, - height: - 80, - ), + transform: + new Matrix4.rotationZ( + 5.837200), ), + ), + Container( + margin: EdgeInsets + .fromLTRB( + 0, + 16, + 0, + 0), + alignment: + Alignment + .center, + child: Image + .network( + model + .parentProducts[ + index] + .images + .isNotEmpty + ? model + .parentProducts[index] + .images[0] + .thumb + : 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/No_image_3x4.svg/1200px-No_image_3x4.svg.png', + fit: BoxFit + .cover, + height: 80, + ), + ), // Container( // width: model.parentProducts[index].rxMessage != // null @@ -882,280 +891,67 @@ class _ParentCategorisePageState extends State { // .w400, // // ), // ), - ], - ), - Container( - margin: EdgeInsets - .symmetric( - horizontal: - 6, - vertical: 0, - ), - child: Column( - crossAxisAlignment: - CrossAxisAlignment - .start, - children: [ - if (model - .parentProducts[index] - .discountName != - null) - Container( - width: - double.infinity, - height: - 13.0, - decoration: - BoxDecoration( - color: - Color(0xff5AB145), - ), - child: - Center( - child: - Texts( - model.parentProducts[index].discountName, - regular: true, - color: Colors.white, - fontSize: 10.4, - ), - ), - ), - Texts( - projectViewModel.isArabic - ? model.parentProducts[index].namen - : model.parentProducts[index].name, - regular: - true, - fontSize: - 12, - fontWeight: - FontWeight.w700, - ), - Padding( - padding: const EdgeInsets.only( - top: - 4, - bottom: - 4), - child: - Texts( - "SAR ${model.parentProducts[index].price}", - bold: - true, - fontSize: - 14, - ), - ), - Row( - children: [ -// StarRating( -// totalAverage: model.parentProducts[index].approvedRatingSum > 0 -// ? (model.parentProducts[index].approvedRatingSum.toDouble() / model.parentProducts[index].approvedRatingSum.toDouble()).toDouble() -// : 0, -// forceStars: true), - RatingBar - .readOnly( - initialRating: - model.parentProducts[index].approvedRatingSum.toDouble(), - size: - 15.0, - filledColor: - Colors.yellow[700], - emptyColor: - Colors.grey[500], - isHalfAllowed: - true, - halfFilledIcon: - Icons.star_half, - filledIcon: - Icons.star, - emptyIcon: - Icons.star, - ), - Texts( - "(${model.parentProducts[index].approvedTotalReviews})", - regular: - true, - fontSize: - 10, - fontWeight: - FontWeight.w400, - ) - ], - ), - ], - ), - ), - ], - ), - ), - ), - onTap: () => { - Navigator.push( - context, - FadePage( - page: ProductDetailPage( - model.parentProducts[ - index]), - )), - }, - )); - }, - ), - ) - : Container( - height: - model.parentProducts.length * - MediaQuery.of(context) - .size - .height * - 0.122, - child: ListView.builder( - physics: - NeverScrollableScrollPhysics(), - itemCount: model - .parentProducts.length, - itemBuilder: - (BuildContext context, - int index) { - return InkWell( - child: Card( - child: Row( - children: [ - Stack( - children: [ - Column( - children: [ - Container( - decoration: - BoxDecoration(), - child: - Padding( - padding: - EdgeInsets.only( - left: - 9.0, - top: - 8.0, - right: - 10.0, - ), - ), - ), - Container( - margin: EdgeInsets - .fromLTRB( - 0, - 0, - 0, - 0), - alignment: - Alignment - .center, - child: model - .parentProducts[ - index] - .images - .isNotEmpty - ? Image - .network( - model.parentProducts[index].images[0].thumb, - fit: BoxFit.contain, - height: 70, - ) - : Text( - TranslationBase.of(context).noImage), - ), - ], - ), - Column( - children: [ - Container( - width: model.parentProducts[index].rxMessage != - null - ? MediaQuery.of(context).size.width / - 5.3 - : 0, - padding: - EdgeInsets.all( - 4), - decoration: - BoxDecoration( - color: Color( - 0xffb23838), - borderRadius: - BorderRadius.only(topLeft: Radius.circular(6)), - ), - child: model.parentProducts[index].rxMessage != - null - ? Texts( - projectProvider.isArabic ? model.parentProducts[index].rxMessagen : model.parentProducts[index].rxMessage, - color: Colors.white, - regular: true, - fontSize: 10, - fontWeight: FontWeight.w400, - ) - : Texts( - ""), -// Texts( -// model.parentProducts[index].rxMessage != null ? model.parentProducts[index].rxMessage : "", -// color: Colors.white, -// regular: true, -// fontSize: 10, -// fontWeight: FontWeight.w400, -// ), - ), - ], - ), ], ), Container( margin: EdgeInsets .symmetric( - horizontal: 0, + horizontal: 6, vertical: 0, ), child: Column( - mainAxisAlignment: - MainAxisAlignment - .spaceAround, crossAxisAlignment: CrossAxisAlignment .start, children: [ - SizedBox( - height: 4.0, - ), - Container( - width: MediaQuery.of(context) - .size - .width * - 0.635, - child: - Texts( - projectViewModel - .isArabic - ? model - .parentProducts[ - index] - .namen - : model + if (model + .parentProducts[ + index] + .discountName != + null) + Container( + width: double + .infinity, + height: + 13.0, + decoration: + BoxDecoration( + color: Color( + 0xff5AB145), + ), + child: + Center( + child: + Texts( + model .parentProducts[index] - .name, - regular: - true, - fontSize: - 13.2, - fontWeight: - FontWeight - .w500, - maxLines: - 5, + .discountName, + regular: + true, + color: + Colors.white, + fontSize: + 10.4, + ), + ), ), - ), - SizedBox( - height: 8.0, + Texts( + projectViewModel + .isArabic + ? model + .parentProducts[ + index] + .namen + : model + .parentProducts[index] + .name, + regular: + true, + fontSize: + 12, + fontWeight: + FontWeight + .w700, ), Padding( padding: const EdgeInsets @@ -1174,11 +970,11 @@ class _ParentCategorisePageState extends State { ), Row( children: [ -// StarRating( -// totalAverage: model.parentProducts[index].approvedRatingSum > 0 -// ? (model.parentProducts[index].approvedRatingSum.toDouble() / model.parentProducts[index].approvedRatingSum.toDouble()).toDouble() -// : 0, -// forceStars: true), +// StarRating( +// totalAverage: model.parentProducts[index].approvedRatingSum > 0 +// ? (model.parentProducts[index].approvedRatingSum.toDouble() / model.parentProducts[index].approvedRatingSum.toDouble()).toDouble() +// : 0, +// forceStars: true), RatingBar .readOnly( initialRating: model @@ -1214,11 +1010,258 @@ class _ParentCategorisePageState extends State { ], ), ), - widget.authenticatedUserObject - .isLogin - ? Container( - child: IconButton( - icon: Icon( + ], + ), + ), + ), + onTap: () => { + Navigator.push( + context, + FadePage( + page: ProductDetailPage( + model.parentProducts[ + index]), + )), + }, + )); + }, + ), + ) + : Container( + height: model.parentProducts.length * + MediaQuery.of(context) + .size + .height * + 0.122, + child: ListView.builder( + physics: + NeverScrollableScrollPhysics(), + itemCount: + model.parentProducts.length, + itemBuilder: + (BuildContext context, + int index) { + return InkWell( + child: Card( + child: Row( + children: [ + Stack( + children: [ + Column( + children: [ + Container( + decoration: + BoxDecoration(), + child: + Padding( + padding: + EdgeInsets + .only( + left: 9.0, + top: 8.0, + right: + 10.0, + ), + ), + ), + Container( + margin: EdgeInsets + .fromLTRB( + 0, + 0, + 0, + 0), + alignment: + Alignment + .center, + child: model + .parentProducts[ + index] + .images + .isNotEmpty + ? Image + .network( + model + .parentProducts[index] + .images[0] + .thumb, + fit: BoxFit + .contain, + height: + 70, + ) + : Text(TranslationBase.of( + context) + .noImage), + ), + ], + ), + Column( + children: [ + Container( + width: model.parentProducts[index].rxMessage != + null + ? MediaQuery.of(context) + .size + .width / + 5.3 + : 0, + padding: + EdgeInsets + .all( + 4), + decoration: + BoxDecoration( + color: Color( + 0xffb23838), + borderRadius: + BorderRadius.only( + topLeft: + Radius.circular(6)), + ), + child: model.parentProducts[index] + .rxMessage != + null + ? Texts( + projectProvider.isArabic + ? model.parentProducts[index].rxMessagen + : model.parentProducts[index].rxMessage, + color: + Colors.white, + regular: + true, + fontSize: + 10, + fontWeight: + FontWeight.w400, + ) + : Texts(""), +// Texts( +// model.parentProducts[index].rxMessage != null ? model.parentProducts[index].rxMessage : "", +// color: Colors.white, +// regular: true, +// fontSize: 10, +// fontWeight: FontWeight.w400, +// ), + ), + ], + ), + ], + ), + Container( + margin: EdgeInsets + .symmetric( + horizontal: 0, + vertical: 0, + ), + child: Column( + mainAxisAlignment: + MainAxisAlignment + .spaceAround, + crossAxisAlignment: + CrossAxisAlignment + .start, + children: [ + SizedBox( + height: 4.0, + ), + Container( + width: MediaQuery.of( + context) + .size + .width * + 0.635, + child: Texts( + projectViewModel + .isArabic + ? model + .parentProducts[ + index] + .namen + : model + .parentProducts[ + index] + .name, + regular: true, + fontSize: + 13.2, + fontWeight: + FontWeight + .w500, + maxLines: 5, + ), + ), + SizedBox( + height: 8.0, + ), + Padding( + padding: + const EdgeInsets + .only( + top: 4, + bottom: + 4), + child: Texts( + "SAR ${model.parentProducts[index].price}", + bold: true, + fontSize: 14, + ), + ), + Row( + children: [ +// StarRating( +// totalAverage: model.parentProducts[index].approvedRatingSum > 0 +// ? (model.parentProducts[index].approvedRatingSum.toDouble() / model.parentProducts[index].approvedRatingSum.toDouble()).toDouble() +// : 0, +// forceStars: true), + RatingBar + .readOnly( + initialRating: model + .parentProducts[ + index] + .approvedRatingSum + .toDouble(), + size: 15.0, + filledColor: + Colors.yellow[ + 700], + emptyColor: + Colors.grey[ + 500], + isHalfAllowed: + true, + halfFilledIcon: + Icons + .star_half, + filledIcon: + Icons + .star, + emptyIcon: + Icons + .star, + ), + Texts( + "(${model.parentProducts[index].approvedTotalReviews})", + regular: + true, + fontSize: + 10, + fontWeight: + FontWeight + .w400, + ) + ], + ), + ], + ), + ), + widget.authenticatedUserObject + .isLogin + ? Container( + child: + IconButton( + icon: + Icon( Icons .shopping_cart, size: @@ -1226,7 +1269,8 @@ class _ParentCategorisePageState extends State { color: CustomColors.green, ), - onPressed: () async { + onPressed: + () async { if (model.parentProducts[index].rxMessage == null) { GifLoaderDialogUtils.showMyDialog(context); @@ -1238,66 +1282,54 @@ class _ParentCategorisePageState extends State { AppToast.showErrorToast(message: TranslationBase.of(context).needPrescription); } }), - ) - : Container(), - ], - ), - ), - onTap: () => { - Navigator.push( - context, - FadePage( - page: ProductDetailPage( - model.parentProducts[ - index]), - )), - }, - ); - }), - ) - : Padding( - padding: const EdgeInsets.all(12.0), - child: Container( - child: Center( - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Padding( - padding: - const EdgeInsets.all( - 8.0), - child: Image.asset( - 'assets/images/new-design/empty_box.png', - width: 100, - height: 100, - fit: BoxFit.cover, + ) + : Container(), + ], ), ), - Padding( - padding: - const EdgeInsets.all( - 8.0), - child: Text( - TranslationBase.of( - context) - .noData, - // 'There is no data', - style: TextStyle( - fontSize: 30), - ), - ) - ], + onTap: () => { + Navigator.push( + context, + FadePage( + page: ProductDetailPage( + model.parentProducts[ + index]), + )), + }, + ); + }), + ) + : Padding( + padding: const EdgeInsets.all(12.0), + child: Container( + child: Center( + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Padding( + padding: + const EdgeInsets.all(8.0), + child: Image.asset( + 'assets/images/new-design/empty_box.png', + width: 100, + height: 100, + fit: BoxFit.cover, + ), ), - ), + Padding( + padding: + const EdgeInsets.all(8.0), + child: Text( + TranslationBase.of(context) + .noData, + // 'There is no data', + style: + TextStyle(fontSize: 30), + ), + ) + ], ), - ) - : Center( - child: CircularProgressIndicator( - backgroundColor: Colors.white, - valueColor: - AlwaysStoppedAnimation( - Colors.grey[500], ), ), ) diff --git a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart index 524501e1..0e5f1731 100644 --- a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart +++ b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart @@ -121,7 +121,7 @@ class _CartOrderPageState extends State { // '${value.quantityCount ?? 0}'); } }); - })) + }, model)) ], ), ), diff --git a/lib/pages/pharmacies/widgets/ProductOrderItem.dart b/lib/pages/pharmacies/widgets/ProductOrderItem.dart index 11976175..e6441fe2 100644 --- a/lib/pages/pharmacies/widgets/ProductOrderItem.dart +++ b/lib/pages/pharmacies/widgets/ProductOrderItem.dart @@ -1,6 +1,9 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -11,8 +14,10 @@ class ProductOrderItem extends StatefulWidget { final ShoppingCart item; final VoidCallback changeCartItems; final VoidCallback deleteCartItems; + final OrderPreviewViewModel model; - ProductOrderItem(this.item, this.changeCartItems, this.deleteCartItems); + ProductOrderItem( + this.item, this.changeCartItems, this.deleteCartItems, this.model); @override _ProductOrderItemState createState() => _ProductOrderItemState(); @@ -40,7 +45,8 @@ class _ProductOrderItemState extends State { leading: InkWell( onTap: () => {widget.deleteCartItems()}, child: Icon( - FontAwesomeIcons.trashAlt,size: 15, + FontAwesomeIcons.trashAlt, + size: 15, color: Colors.grey.shade700, ), ), @@ -50,17 +56,18 @@ class _ProductOrderItemState extends State { crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ - (widget.item.product.images != null && widget.item.product.images.length > 0) + (widget.item.product.images != null && + widget.item.product.images.length > 0) ? Image.network( - widget.item.product.images[0].src, - fit: BoxFit.cover, - height: 80, - ) + widget.item.product.images[0].src, + fit: BoxFit.cover, + height: 80, + ) : Image.asset( - "assets/images/no_image.png", - fit: BoxFit.cover, - height: 80, - ), + "assets/images/no_image.png", + fit: BoxFit.cover, + height: 80, + ), Expanded( child: Container( margin: @@ -95,13 +102,17 @@ class _ProductOrderItemState extends State { child: Row( children: [ InkWell( - onTap: () => - {_quantityOnChangeClick(Operation.dec)}, + onTap: () => widget.model.error.isEmpty + ? {_quantityOnChangeClick(Operation.dec)} + : Utils.showErrorToast( + widget.model.error), child: Container( width: 25, height: 25, child: Icon( - Icons.remove, color: Colors.grey.shade400, size: 20, + Icons.remove, + color: Colors.grey.shade400, + size: 20, ), decoration: BoxDecoration( border: Border.all( @@ -129,7 +140,8 @@ class _ProductOrderItemState extends State { if (value == null) { widget.item.quantity = 0; } else { - widget.item.quantity = int.parse(text); + widget.item.quantity = + int.parse(text); } _totalPrice = "${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}"; @@ -138,13 +150,17 @@ class _ProductOrderItemState extends State { )), ), InkWell( - onTap: () => - {_quantityOnChangeClick(Operation.inc)}, + onTap: () => widget.model.error == null + ? {_quantityOnChangeClick(Operation.inc)} + : Utils.showErrorToast( + widget.model.error), child: Container( width: 25, height: 25, child: Icon( - Icons.add, color: Colors.grey.shade400, size: 20, + Icons.add, + color: Colors.grey.shade400, + size: 20, ), decoration: BoxDecoration( border: Border.all( @@ -169,21 +185,21 @@ class _ProductOrderItemState extends State { fontSize: 12, fontWeight: FontWeight.bold, ), - widget.item.product.stockQuantity == 0 ? - Texts( - projectProvider.isArabic - ? widget.item.product.stockAvailabilityn - : widget.item.product.stockAvailability, - fontWeight: FontWeight.normal, - fontSize: 13, - color:Colors.red, - - ): Texts(""), + widget.item.product.stockQuantity == 0 + ? Texts( + projectProvider.isArabic + ? widget.item.product + .stockAvailabilityn + : widget.item.product + .stockAvailability, + fontWeight: FontWeight.normal, + fontSize: 13, + color: Colors.red, + ) + : Texts(""), ], ), ), - - ], ), ) @@ -209,6 +225,7 @@ class _ProductOrderItemState extends State { _quantityOnChangeClick(Operation operation) { int newValue = 0; + setState(() { switch (operation) { case Operation.inc: diff --git a/lib/pages/sub_categorise_page.dart b/lib/pages/sub_categorise_page.dart index b7c5d244..4bc069dc 100644 --- a/lib/pages/sub_categorise_page.dart +++ b/lib/pages/sub_categorise_page.dart @@ -1,3 +1,4 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/pharmacy/categorise_parent_model.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; @@ -18,6 +19,7 @@ import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:rating_bar/rating_bar.dart'; import 'base/base_view.dart'; @@ -55,6 +57,10 @@ class _SubCategorisePageState extends State { color: Colors.blue, size: 29.0, ); + + int pageIndex = 1; + + RefreshController controller = RefreshController(); List entityList = List(); List entityListBrands = List(); @@ -65,7 +71,8 @@ class _SubCategorisePageState extends State { ProjectViewModel projectViewModel = Provider.of(context); ProjectViewModel projectProvider = Provider.of(context); return BaseView( - onModelReady: (model) => model.getSubCategorise(i: id), + onModelReady: (model) => model.getSubCategorise( + i: id, pageIndex: pageIndex, isLoading: false, context: context), allowAny: true, builder: (BuildContext context, PharmacyCategoriseViewModel model, Widget child) => @@ -75,9 +82,26 @@ class _SubCategorisePageState extends State { isShowAppBar: true, backgroundColor: Colors.white, isShowDecPage: false, - //baseViewModel: model, - body: NetworkBaseView( - baseViewModel: model, + baseViewModel: model, + body: SmartRefresher( + controller: controller, + enablePullDown: false, + enablePullUp: true, + onLoading: () async { + setState(() { + ++pageIndex; + }); + await model.getSubProducts( + pageIndex: pageIndex, + i: id, + isLoading: true, + context: context); + if (model.state != ViewState.BusyLocal && pageIndex < 5) { + controller.loadComplete(); + } else { + controller.loadFailed(); + } + }, child: SingleChildScrollView( child: Container( child: Column(