checkStockAsset method
dynamic
checkStockAsset(
- BuildContext context,
- CheckStockContentModel? model,
- bool isFromCheckIn,
- int currentPage,
Implementation
checkStockAsset(BuildContext context, CheckStockContentModel? model,
bool isFromCheckIn, int currentPage) {
final StockDetailsController controller = Get.put(StockDetailsController());
final ScrollController scrollController = ScrollController();
final storage = GetStorage();
String? query;
TextEditingController searchController = TextEditingController();
bool searchSubmitted = false;
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
Future<void> _refresh() async {
currentPage = 1;
controller.callDealerAssetApi("NEW", storage.read("PARTNER_ID_LOGIN"),
model?.productCode ?? "", null, model, 1, 10,
isFromCheckin: isFromCheckIn, query: "");
}
void onScroll() {
if (scrollController.position.maxScrollExtent ==
scrollController.position.pixels &&
controller.dealerAssetList.length < controller.totalList) {
controller.isLoadingMore.value = true;
currentPage++; // Assuming each page has 10 items
controller.callDealerAssetApi(
"NEW",
storage.read("PARTNER_ID_LOGIN"),
model?.productCode ?? "",
null,
model,
currentPage,
10,
isFromCheckin: isFromCheckIn,
query: query,
);
}
}
scrollController.addListener(onScroll);
searchedList() {
print(query);
currentPage = 1;
controller.callDealerAssetApi(
"NEW",
storage.read("PARTNER_ID_LOGIN"),
model?.productCode ?? "",
null,
model,
currentPage,
10,
isFromCheckin: isFromCheckIn,
query: query,
);
}
showModalBottomSheet<void>(
context: context,
enableDrag: false,
isScrollControlled: true,
isDismissible: true,
backgroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
SizeConstant.getHeightWithScreen(20),
),
),
builder: (BuildContext context) {
return Container(
height: SizeConstant.getHeightWithScreen(600),
decoration: BoxDecoration(
color: ColorConstant.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(
SizeConstant.getHeightWithScreen(20),
),
topRight: Radius.circular(
SizeConstant.getHeightWithScreen(20),
),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
top: SizeConstant.getHeightWithScreen(26),
left: SizeConstant.getHeightWithScreen(15),
right: SizeConstant.getHeightWithScreen(15),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
localization.translate("scannedAssets"),
style: TextStyle(
fontSize: SizeConstant.largeFont,
fontWeight: FontWeight.w500,
color: ColorConstant.black,
),
),
GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: SizedBox(
child: Icon(
Icons.close,
color: ColorConstant.black,
size: SizeConstant.getHeightWithScreen(20),
),
),
),
]),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(12),
),
Padding(
padding: EdgeInsets.only(
left: SizeConstant.getHeightWithScreen(15),
right: SizeConstant.getHeightWithScreen(15)),
child: Container(
padding: EdgeInsets.all(
SizeConstant.getHeightWithScreen(15),
),
decoration: BoxDecoration(
color: ColorConstant.creem2,
boxShadow: [
BoxShadow(
color: ColorConstant.shadowColor,
blurRadius: 6,
blurStyle: BlurStyle.outer, //extend the shadow
),
],
borderRadius: BorderRadius.all(
Radius.circular(SizeConstant.getHeightWithScreen(15)),
)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: SizeConstant.getHeightWithScreen(180),
child: Text(
model?.productName ?? "-",
style: TextStyle(
overflow: TextOverflow.visible,
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w600,
color: ColorConstant.black3,
),
),
),
Container(
padding: EdgeInsets.symmetric(
horizontal:
SizeConstant.getHeightWithScreen(6),
vertical:
SizeConstant.getHeightWithScreen(2)),
decoration: BoxDecoration(
color: ColorConstant.grey8,
border: Border.all(color: ColorConstant.grey8),
borderRadius: BorderRadius.all(
Radius.circular(
SizeConstant.getHeightWithScreen(19)),
),
),
child: Row(
children: [
Text(
localization.translate('quantity'),
style: TextStyle(
overflow: TextOverflow.visible,
fontSize: SizeConstant.xSmallFont,
fontWeight: FontWeight.w400,
color:
ColorConstant.black.withOpacity(0.60),
),
),
Text(
' ${model?.assetCount.toString()}',
style: TextStyle(
overflow: TextOverflow.visible,
fontSize: SizeConstant.mediumSmallFont,
fontWeight: FontWeight.w600,
color: ColorConstant.dashboardSecColor,
),
),
],
)),
],
),
SizedBox(
height: SizeConstant.getHeightWithScreen(2),
),
Text(
model?.productCode ?? "-",
style: TextStyle(
overflow: TextOverflow.visible,
fontSize: SizeConstant.xSmallFont,
fontWeight: FontWeight.w500,
color: ColorConstant.grey11,
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(8),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${Helper.amountWithCurrency("USD", model?.unitPrice ?? 0.0)}/unit',
style: TextStyle(
overflow: TextOverflow.visible,
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w500,
color: ColorConstant.black,
),
),
Row(children: [
Text(
localization.translate("totalPrice"),
style: TextStyle(
overflow: TextOverflow.visible,
fontSize: SizeConstant.xSmallFont,
fontWeight: FontWeight.w400,
color: ColorConstant.black,
),
),
Text(
' ${Helper.amountWithCurrency("USD", getTotalPrice(model?.unitPrice, double.parse(model!.assetCount.toString())))}',
style: TextStyle(
overflow: TextOverflow.visible,
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w600,
color: ColorConstant.black,
),
),
]),
],
)
],
),
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(19),
),
SearchBarWidget(
padding: EdgeInsets.symmetric(
horizontal: SizeConstant.getHeightWithScreen(16),
),
controller: searchController,
hintText: 'search'.tr,
textInputAction: TextInputAction.search,
textInputType: TextInputType.phone,
onSubmit: (text) {
if (query == null) {
return;
} else if (query!.isEmpty) {
return;
}
searchSubmitted = true;
Helper.hideKeyboard();
searchedList();
},
onChanged: (text) {
query = text;
if (query != null && query!.isEmpty && searchSubmitted) {
searchSubmitted = false;
Helper.hideKeyboard();
searchedList();
}
},
borderColor: ColorConstant.shadowColor,
prefixIcon: GestureDetector(
onTap: () {
if (searchSubmitted) {
searchController.text = "";
query = "";
searchSubmitted = false;
Helper.hideKeyboard();
searchedList();
} else {
Helper.hideKeyboard();
searchController.text = "";
query = "";
}
},
child: Container(
color: Colors.transparent,
padding: EdgeInsets.only(
left: SizeConstant.getHeightWithScreen(10),
right: SizeConstant.getHeightWithScreen(10),
),
child: Image.asset(
"assets/images/back_arrow.png",
package: Constants.packageName,
height: SizeConstant.getHeightWithScreen(13),
width: SizeConstant.getHeightWithScreen(13),
),
),
),
suffixIcon: GestureDetector(
onTap: () {
if (query == null) {
return;
} else if (query!.isEmpty) {
return;
}
searchSubmitted = true;
Helper.hideKeyboard();
searchedList();
},
child: Container(
color: Colors.transparent,
padding: EdgeInsets.only(
left: SizeConstant.getHeightWithScreen(10),
right: SizeConstant.getHeightWithScreen(10),
),
child: SvgPicture.asset(
"assets/images/search.svg",
package: Constants.packageName,
height: SizeConstant.getHeightWithScreen(13),
width: SizeConstant.getHeightWithScreen(13),
),
),
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(19),
),
Padding(
padding: EdgeInsets.only(
left: SizeConstant.getHeightWithScreen(30),
right: SizeConstant.getHeightWithScreen(30)),
child: Table(
columnWidths: const {
0: FlexColumnWidth(1),
1: FlexColumnWidth(1),
2: FlexColumnWidth(1),
},
children: [
TableRow(
children: [
Text(
localization.translate("serialNumber"),
style: TextStyle(
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w500,
color: ColorConstant.black2,
),
),
Text(
localization.translate("purchaseDate"),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w500,
color: ColorConstant.black2,
),
),
Text(
localization.translate("expiryDate"),
textAlign: TextAlign.right,
style: TextStyle(
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w500,
color: ColorConstant.black2,
),
)
],
),
],
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(9),
),
Expanded(
child: Obx(
() => controller.dealerSearchedAssetList.isEmpty
? Center(
child: Text(localization.translate("noDataFound")),
)
: RefreshIndicator.adaptive(
color: ColorConstant.primaryColor,
triggerMode: RefreshIndicatorTriggerMode.anywhere,
key: _refreshIndicatorKey,
onRefresh: _refresh,
child: ListView.separated(
physics: const AlwaysScrollableScrollPhysics(),
controller: scrollController,
shrinkWrap: false,
separatorBuilder:
(BuildContext context, int index) => SizedBox(
height: SizeConstant.getHeightWithScreen(5),
),
itemCount:
controller.dealerSearchedAssetList.length + 1,
itemBuilder: (ctx, id) {
if (id <
controller.dealerSearchedAssetList.length) {
return Container(
decoration: BoxDecoration(
color: ColorConstant.white2,
borderRadius: BorderRadius.all(
Radius.circular(
SizeConstant.getHeightWithScreen(5),
),
),
),
margin: const EdgeInsets.symmetric(
horizontal: 15,
),
padding: EdgeInsets.symmetric(
horizontal:
SizeConstant.getHeightWithScreen(15),
vertical:
SizeConstant.getHeightWithScreen(10)),
child: Table(
columnWidths: const {
0: FlexColumnWidth(1),
1: FlexColumnWidth(1),
2: FlexColumnWidth(1),
},
children: [
TableRow(
children: [
AnimatedTooltip(
content: Text(
controller
.dealerSearchedAssetList[id]
.serialnumber!,
style: Constants.tooltipTextStyle,
),
child: GestureDetector(
onLongPress: () async {
await Helper.copyToClipBoard(
controller
.dealerSearchedAssetList[
id]
.serialnumber);
},
child: Text(
controller
.dealerSearchedAssetList[id]
.serialnumber!,
style: TextStyle(
overflow:
TextOverflow.ellipsis,
fontSize:
SizeConstant.smallFont,
fontWeight: FontWeight.w500,
color: ColorConstant.black2,
),
),
),
),
Text(
formatDate(
controller
.dealerSearchedAssetList[id]
.purchaseDate,
'dd-MM-yyyy',
'dd MMM yyyy',
),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: SizeConstant.xSmallFont,
fontWeight: FontWeight.w400,
color: ColorConstant.grey32,
),
),
Text(
formatDate(
controller
.dealerSearchedAssetList[id]
.expiryDate,
'yyyy-MM-dd HH:mm:ss',
'dd MMM yyyy',
),
textAlign: TextAlign.right,
style: TextStyle(
fontSize: SizeConstant.xSmallFont,
fontWeight: FontWeight.w400,
color: ColorConstant.grey32,
),
),
],
),
],
),
);
} else {
return controller
.dealerSearchedAssetList.length <
controller.totalList
? Center(
child:
CircularProgressIndicator.adaptive(
valueColor: AlwaysStoppedAnimation(
ColorConstant.primaryColor,
),
),
)
: const SizedBox();
}
},
),
),
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(20),
),
],
),
);
},
);
}