sub categories pagnation

merge-requests/521/head
hussam al-habibeh 4 years ago
parent e917da9183
commit ff86dcbdc0

@ -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; hasError = false;
_subProductsList.clear(); if (isLoading == false) {
_subProductsList.clear();
}
String endPoint = id != null String endPoint = id != null
? GET_SUB_PRODUCTS + "$id" + '&page=1&limit=50' ? GET_SUB_PRODUCTS + "$id" + '&page=' + '$pageIndex' + '&limit=24'
: GET_SUB_PRODUCTS + ""; : GET_SUB_PRODUCTS + "";
await baseAppClient.getPharmacy( await baseAppClient.getPharmacy(
endPoint, endPoint,

@ -121,7 +121,7 @@ class PharmacyCategoriseViewModel extends BaseViewModel {
hasError = false; hasError = false;
// _insuranceCardService.clearInsuranceCard(); // _insuranceCardService.clearInsuranceCard();
setState(ViewState.BusyLocal); setState(ViewState.BusyLocal);
//GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await _pharmacyCategoriseService.getParentProducts( await _pharmacyCategoriseService.getParentProducts(
id: i, pageNumber: pageIndex, isLoading: isLoading); id: i, pageNumber: pageIndex, isLoading: isLoading);
if (_pharmacyCategoriseService.hasError) { if (_pharmacyCategoriseService.hasError) {
@ -129,31 +129,45 @@ class PharmacyCategoriseViewModel extends BaseViewModel {
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
} else } else
setState(ViewState.Idle); 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; hasError = false;
// _insuranceCardService.clearInsuranceCard(); // _insuranceCardService.clearInsuranceCard();
setState(ViewState.Busy); setState(ViewState.Busy);
await _pharmacyCategoriseService.getSubCategorise(id: i); await _pharmacyCategoriseService.getSubCategorise(
id: i,
);
if (_pharmacyCategoriseService.hasError) { if (_pharmacyCategoriseService.hasError) {
error = _pharmacyCategoriseService.error; error = _pharmacyCategoriseService.error;
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
} else } 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; hasError = false;
// _insuranceCardService.clearInsuranceCard(); // _insuranceCardService.clearInsuranceCard();
setState(ViewState.Busy); setState(ViewState.BusyLocal);
await _pharmacyCategoriseService.getSubProducts(id: i); GifLoaderDialogUtils.showMyDialog(context);
await _pharmacyCategoriseService.getSubProducts(
id: i, pageIndex: pageIndex, isLoading: isLoading);
if (_pharmacyCategoriseService.hasError) { if (_pharmacyCategoriseService.hasError) {
error = _pharmacyCategoriseService.error; error = _pharmacyCategoriseService.error;
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
} else } else
setState(ViewState.Idle); setState(ViewState.Idle);
GifLoaderDialogUtils.hideDialog(context);
} }
Future getFinalProducts({String i}) async { Future getFinalProducts({String i}) async {

File diff suppressed because it is too large Load Diff

@ -121,7 +121,7 @@ class _CartOrderPageState extends State<CartOrderPage> {
// '${value.quantityCount ?? 0}'); // '${value.quantityCount ?? 0}');
} }
}); });
})) }, model))
], ],
), ),
), ),

@ -1,6 +1,9 @@
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.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/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.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:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -11,8 +14,10 @@ class ProductOrderItem extends StatefulWidget {
final ShoppingCart item; final ShoppingCart item;
final VoidCallback changeCartItems; final VoidCallback changeCartItems;
final VoidCallback deleteCartItems; final VoidCallback deleteCartItems;
final OrderPreviewViewModel model;
ProductOrderItem(this.item, this.changeCartItems, this.deleteCartItems); ProductOrderItem(
this.item, this.changeCartItems, this.deleteCartItems, this.model);
@override @override
_ProductOrderItemState createState() => _ProductOrderItemState(); _ProductOrderItemState createState() => _ProductOrderItemState();
@ -40,7 +45,8 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
leading: InkWell( leading: InkWell(
onTap: () => {widget.deleteCartItems()}, onTap: () => {widget.deleteCartItems()},
child: Icon( child: Icon(
FontAwesomeIcons.trashAlt,size: 15, FontAwesomeIcons.trashAlt,
size: 15,
color: Colors.grey.shade700, color: Colors.grey.shade700,
), ),
), ),
@ -50,17 +56,18 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ 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( ? Image.network(
widget.item.product.images[0].src, widget.item.product.images[0].src,
fit: BoxFit.cover, fit: BoxFit.cover,
height: 80, height: 80,
) )
: Image.asset( : Image.asset(
"assets/images/no_image.png", "assets/images/no_image.png",
fit: BoxFit.cover, fit: BoxFit.cover,
height: 80, height: 80,
), ),
Expanded( Expanded(
child: Container( child: Container(
margin: margin:
@ -95,13 +102,17 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
child: Row( child: Row(
children: [ children: [
InkWell( InkWell(
onTap: () => onTap: () => widget.model.error.isEmpty
{_quantityOnChangeClick(Operation.dec)}, ? {_quantityOnChangeClick(Operation.dec)}
: Utils.showErrorToast(
widget.model.error),
child: Container( child: Container(
width: 25, width: 25,
height: 25, height: 25,
child: Icon( child: Icon(
Icons.remove, color: Colors.grey.shade400, size: 20, Icons.remove,
color: Colors.grey.shade400,
size: 20,
), ),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
@ -129,7 +140,8 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
if (value == null) { if (value == null) {
widget.item.quantity = 0; widget.item.quantity = 0;
} else { } else {
widget.item.quantity = int.parse(text); widget.item.quantity =
int.parse(text);
} }
_totalPrice = _totalPrice =
"${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}"; "${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}";
@ -138,13 +150,17 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
)), )),
), ),
InkWell( InkWell(
onTap: () => onTap: () => widget.model.error == null
{_quantityOnChangeClick(Operation.inc)}, ? {_quantityOnChangeClick(Operation.inc)}
: Utils.showErrorToast(
widget.model.error),
child: Container( child: Container(
width: 25, width: 25,
height: 25, height: 25,
child: Icon( child: Icon(
Icons.add, color: Colors.grey.shade400, size: 20, Icons.add,
color: Colors.grey.shade400,
size: 20,
), ),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
@ -169,21 +185,21 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
widget.item.product.stockQuantity == 0 ? widget.item.product.stockQuantity == 0
Texts( ? Texts(
projectProvider.isArabic projectProvider.isArabic
? widget.item.product.stockAvailabilityn ? widget.item.product
: widget.item.product.stockAvailability, .stockAvailabilityn
fontWeight: FontWeight.normal, : widget.item.product
fontSize: 13, .stockAvailability,
color:Colors.red, fontWeight: FontWeight.normal,
fontSize: 13,
): Texts(""), color: Colors.red,
)
: Texts(""),
], ],
), ),
), ),
], ],
), ),
) )
@ -209,6 +225,7 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
_quantityOnChangeClick(Operation operation) { _quantityOnChangeClick(Operation operation) {
int newValue = 0; int newValue = 0;
setState(() { setState(() {
switch (operation) { switch (operation) {
case Operation.inc: case Operation.inc:

@ -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/model/pharmacy/categorise_parent_model.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.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:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:rating_bar/rating_bar.dart'; import 'package:rating_bar/rating_bar.dart';
import 'base/base_view.dart'; import 'base/base_view.dart';
@ -55,6 +57,10 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
color: Colors.blue, color: Colors.blue,
size: 29.0, size: 29.0,
); );
int pageIndex = 1;
RefreshController controller = RefreshController();
List<CategoriseParentModel> entityList = List(); List<CategoriseParentModel> entityList = List();
List<CategoriseParentModel> entityListBrands = List(); List<CategoriseParentModel> entityListBrands = List();
@ -65,7 +71,8 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
ProjectViewModel projectViewModel = Provider.of(context); ProjectViewModel projectViewModel = Provider.of(context);
ProjectViewModel projectProvider = Provider.of(context); ProjectViewModel projectProvider = Provider.of(context);
return BaseView<PharmacyCategoriseViewModel>( return BaseView<PharmacyCategoriseViewModel>(
onModelReady: (model) => model.getSubCategorise(i: id), onModelReady: (model) => model.getSubCategorise(
i: id, pageIndex: pageIndex, isLoading: false, context: context),
allowAny: true, allowAny: true,
builder: (BuildContext context, PharmacyCategoriseViewModel model, builder: (BuildContext context, PharmacyCategoriseViewModel model,
Widget child) => Widget child) =>
@ -75,9 +82,26 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
isShowAppBar: true, isShowAppBar: true,
backgroundColor: Colors.white, backgroundColor: Colors.white,
isShowDecPage: false, isShowDecPage: false,
//baseViewModel: model, baseViewModel: model,
body: NetworkBaseView( body: SmartRefresher(
baseViewModel: model, 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: SingleChildScrollView(
child: Container( child: Container(
child: Column( child: Column(

Loading…
Cancel
Save