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;
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,

@ -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 {

@ -689,10 +689,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
),
model.parentProducts.isNotEmpty
? styleOne == true
? model.state != ViewState.BusyLocal
? Container(
height:
model.parentProducts.length *
height: model.parentProducts.length *
MediaQuery.of(context)
.size
.height *
@ -709,8 +707,7 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
),
itemCount:
model.parentProducts.length,
itemBuilder:
(BuildContext context,
itemBuilder: (BuildContext context,
int index) {
return NetworkBaseView(
baseViewModel: model,
@ -721,34 +718,33 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
index]
.discountName !=
null
? Color(
0xffFFFF00)
? Color(0xffFFFF00)
: Colors.white,
elevation: 0,
shape: Border(
right: BorderSide(
color: Colors.grey
.shade300,
color: Colors
.grey.shade300,
width: 1,
),
left: BorderSide(
color: Colors.grey
.shade300,
color: Colors
.grey.shade300,
width: 1,
),
bottom: BorderSide(
color: Colors.grey
.shade300,
color: Colors
.grey.shade300,
width: 1,
),
top: BorderSide(
color: Colors.grey
.shade300,
color: Colors
.grey.shade300,
width: 1,
),
),
margin: EdgeInsets
.symmetric(
margin:
EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
@ -756,19 +752,16 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
decoration:
BoxDecoration(
borderRadius:
BorderRadius
.only(
topLeft: Radius
.circular(
BorderRadius.only(
topLeft:
Radius.circular(
110.0),
),
color:
Colors.white,
color: Colors.white,
),
padding: EdgeInsets
.symmetric(
horizontal:
0),
horizontal: 0),
width: MediaQuery.of(
context)
.size
@ -782,7 +775,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
Stack(
children: [
if (model
.parentProducts[index]
.parentProducts[
index]
.discountName !=
null)
RotatedBox(
@ -796,20 +790,29 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
Padding(
padding:
EdgeInsets.only(
right: 5.0,
top: 20.0,
bottom: 5.0,
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,
TranslationBase.of(context)
.offers
.toUpperCase(),
color:
Colors.red,
fontSize:
13.0,
fontWeight:
FontWeight.w900,
),
),
transform:
new Matrix4.rotationZ(5.837200),
new Matrix4.rotationZ(
5.837200),
),
),
Container(
@ -824,13 +827,19 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
.center,
child: Image
.network(
model.parentProducts[index].images.isNotEmpty
? model.parentProducts[index].images[0].thumb
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,
height: 80,
),
),
// Container(
@ -887,8 +896,7 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
Container(
margin: EdgeInsets
.symmetric(
horizontal:
6,
horizontal: 6,
vertical: 0,
),
child: Column(
@ -897,45 +905,58 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
.start,
children: [
if (model
.parentProducts[index]
.parentProducts[
index]
.discountName !=
null)
Container(
width:
double.infinity,
width: double
.infinity,
height:
13.0,
decoration:
BoxDecoration(
color:
Color(0xff5AB145),
color: Color(
0xff5AB145),
),
child:
Center(
child:
Texts(
model.parentProducts[index].discountName,
regular: true,
color: Colors.white,
fontSize: 10.4,
model
.parentProducts[index]
.discountName,
regular:
true,
color:
Colors.white,
fontSize:
10.4,
),
),
),
Texts(
projectViewModel.isArabic
? model.parentProducts[index].namen
: model.parentProducts[index].name,
projectViewModel
.isArabic
? model
.parentProducts[
index]
.namen
: model
.parentProducts[index]
.name,
regular:
true,
fontSize:
12,
fontWeight:
FontWeight.w700,
FontWeight
.w700,
),
Padding(
padding: const EdgeInsets.only(
top:
4,
padding: const EdgeInsets
.only(
top: 4,
bottom:
4),
child:
@ -956,8 +977,10 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
// forceStars: true),
RatingBar
.readOnly(
initialRating:
model.parentProducts[index].approvedRatingSum.toDouble(),
initialRating: model
.parentProducts[index]
.approvedRatingSum
.toDouble(),
size:
15.0,
filledColor:
@ -1005,8 +1028,7 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
),
)
: Container(
height:
model.parentProducts.length *
height: model.parentProducts.length *
MediaQuery.of(context)
.size
.height *
@ -1014,8 +1036,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
child: ListView.builder(
physics:
NeverScrollableScrollPhysics(),
itemCount: model
.parentProducts.length,
itemCount:
model.parentProducts.length,
itemBuilder:
(BuildContext context,
int index) {
@ -1033,11 +1055,10 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
child:
Padding(
padding:
EdgeInsets.only(
left:
9.0,
top:
8.0,
EdgeInsets
.only(
left: 9.0,
top: 8.0,
right:
10.0,
),
@ -1060,12 +1081,18 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
.isNotEmpty
? Image
.network(
model.parentProducts[index].images[0].thumb,
fit: BoxFit.contain,
height: 70,
model
.parentProducts[index]
.images[0]
.thumb,
fit: BoxFit
.contain,
height:
70,
)
: Text(
TranslationBase.of(context).noImage),
: Text(TranslationBase.of(
context)
.noImage),
),
],
),
@ -1074,30 +1101,41 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
Container(
width: model.parentProducts[index].rxMessage !=
null
? MediaQuery.of(context).size.width /
? MediaQuery.of(context)
.size
.width /
5.3
: 0,
padding:
EdgeInsets.all(
EdgeInsets
.all(
4),
decoration:
BoxDecoration(
color: Color(
0xffb23838),
borderRadius:
BorderRadius.only(topLeft: Radius.circular(6)),
BorderRadius.only(
topLeft:
Radius.circular(6)),
),
child: model.parentProducts[index].rxMessage !=
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,
projectProvider.isArabic
? model.parentProducts[index].rxMessagen
: model.parentProducts[index].rxMessage,
color:
Colors.white,
regular:
true,
fontSize:
10,
fontWeight:
FontWeight.w400,
)
: Texts(
""),
: Texts(""),
// Texts(
// model.parentProducts[index].rxMessage != null ? model.parentProducts[index].rxMessage : "",
// color: Colors.white,
@ -1128,12 +1166,12 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
height: 4.0,
),
Container(
width: MediaQuery.of(context)
width: MediaQuery.of(
context)
.size
.width *
0.635,
child:
Texts(
child: Texts(
projectViewModel
.isArabic
? model
@ -1141,35 +1179,32 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
index]
.namen
: model
.parentProducts[index]
.parentProducts[
index]
.name,
regular:
true,
regular: true,
fontSize:
13.2,
fontWeight:
FontWeight
.w500,
maxLines:
5,
maxLines: 5,
),
),
SizedBox(
height: 8.0,
),
Padding(
padding: const EdgeInsets
padding:
const EdgeInsets
.only(
top: 4,
bottom:
4),
child:
Texts(
child: Texts(
"SAR ${model.parentProducts[index].price}",
bold:
true,
fontSize:
14,
bold: true,
fontSize: 14,
),
),
Row(
@ -1182,23 +1217,28 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
RatingBar
.readOnly(
initialRating: model
.parentProducts[index]
.parentProducts[
index]
.approvedRatingSum
.toDouble(),
size:
15.0,
size: 15.0,
filledColor:
Colors.yellow[700],
Colors.yellow[
700],
emptyColor:
Colors.grey[500],
Colors.grey[
500],
isHalfAllowed:
true,
halfFilledIcon:
Icons.star_half,
Icons
.star_half,
filledIcon:
Icons.star,
Icons
.star,
emptyIcon:
Icons.star,
Icons
.star,
),
Texts(
"(${model.parentProducts[index].approvedTotalReviews})",
@ -1207,7 +1247,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
fontSize:
10,
fontWeight:
FontWeight.w400,
FontWeight
.w400,
)
],
),
@ -1217,8 +1258,10 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
widget.authenticatedUserObject
.isLogin
? Container(
child: IconButton(
icon: Icon(
child:
IconButton(
icon:
Icon(
Icons
.shopping_cart,
size:
@ -1226,7 +1269,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
color:
CustomColors.green,
),
onPressed: () async {
onPressed:
() async {
if (model.parentProducts[index].rxMessage ==
null) {
GifLoaderDialogUtils.showMyDialog(context);
@ -1265,8 +1309,7 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
children: [
Padding(
padding:
const EdgeInsets.all(
8.0),
const EdgeInsets.all(8.0),
child: Image.asset(
'assets/images/new-design/empty_box.png',
width: 100,
@ -1276,15 +1319,13 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
),
Padding(
padding:
const EdgeInsets.all(
8.0),
const EdgeInsets.all(8.0),
child: Text(
TranslationBase.of(
context)
TranslationBase.of(context)
.noData,
// 'There is no data',
style: TextStyle(
fontSize: 30),
style:
TextStyle(fontSize: 30),
),
)
],
@ -1292,15 +1333,6 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
),
),
)
: Center(
child: CircularProgressIndicator(
backgroundColor: Colors.white,
valueColor:
AlwaysStoppedAnimation<Color>(
Colors.grey[500],
),
),
)
],
),
),

@ -121,7 +121,7 @@ class _CartOrderPageState extends State<CartOrderPage> {
// '${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/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<ProductOrderItem> {
leading: InkWell(
onTap: () => {widget.deleteCartItems()},
child: Icon(
FontAwesomeIcons.trashAlt,size: 15,
FontAwesomeIcons.trashAlt,
size: 15,
color: Colors.grey.shade700,
),
),
@ -50,7 +56,8 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
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,
@ -95,13 +102,17 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
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<ProductOrderItem> {
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<ProductOrderItem> {
)),
),
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<ProductOrderItem> {
fontSize: 12,
fontWeight: FontWeight.bold,
),
widget.item.product.stockQuantity == 0 ?
Texts(
widget.item.product.stockQuantity == 0
? Texts(
projectProvider.isArabic
? widget.item.product.stockAvailabilityn
: widget.item.product.stockAvailability,
? widget.item.product
.stockAvailabilityn
: widget.item.product
.stockAvailability,
fontWeight: FontWeight.normal,
fontSize: 13,
color:Colors.red,
): Texts(""),
color: Colors.red,
)
: Texts(""),
],
),
),
],
),
)
@ -209,6 +225,7 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
_quantityOnChangeClick(Operation operation) {
int newValue = 0;
setState(() {
switch (operation) {
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/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<SubCategorisePage> {
color: Colors.blue,
size: 29.0,
);
int pageIndex = 1;
RefreshController controller = RefreshController();
List<CategoriseParentModel> entityList = List();
List<CategoriseParentModel> entityListBrands = List();
@ -65,7 +71,8 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
ProjectViewModel projectViewModel = Provider.of(context);
ProjectViewModel projectProvider = Provider.of(context);
return BaseView<PharmacyCategoriseViewModel>(
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<SubCategorisePage> {
isShowAppBar: true,
backgroundColor: Colors.white,
isShowDecPage: false,
//baseViewModel: model,
body: NetworkBaseView(
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(

Loading…
Cancel
Save