Commit 185e0896 authored by Sai Srinivas's avatar Sai Srinivas
Browse files

changes by mohit

parent ee5b7a8e
...@@ -11,6 +11,7 @@ class ProfileResponse { ...@@ -11,6 +11,7 @@ class ProfileResponse {
String? profilePic; String? profilePic;
int? sessionExists; int? sessionExists;
ProfileResponse( ProfileResponse(
{this.totpSecret, {this.totpSecret,
this.empId, this.empId,
......
...@@ -715,17 +715,30 @@ class Accountslistprovider extends ChangeNotifier { ...@@ -715,17 +715,30 @@ class Accountslistprovider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> commonAccountListAPIFunction(context) async {
String? _errorMessage;
String? get errorMessage => _errorMessage;
// Common Account list provider
Future<void> commonAccountListAPIFunction(
BuildContext context, {
bool append = false,
}) async {
try { try {
var prov = Provider.of<HomescreenNotifier>(context, listen: false); var prov = Provider.of<HomescreenNotifier>(context, listen: false);
if (_pageNum == 1) {
if (!append) {
// Fresh load / Refresh
_accountsList.clear(); _accountsList.clear();
_pageNum = 1;
_hasMoreData = true; _hasMoreData = true;
_isLoading = true; _isLoading = true;
notifyListeners(); } else {
_isLoading = true;
} }
if (!_hasMoreData || !_isLoading) return;
_hasMoreData = true;
notifyListeners(); notifyListeners();
final data = await ApiCalling.commonAccountListAPI( final data = await ApiCalling.commonAccountListAPI(
...@@ -735,23 +748,37 @@ class Accountslistprovider extends ChangeNotifier { ...@@ -735,23 +748,37 @@ class Accountslistprovider extends ChangeNotifier {
companyNameController.text, companyNameController.text,
mobileNumberController.text, mobileNumberController.text,
); );
if (data != null) { debugPrint('empId: ${prov.empId}, session: ${prov.session}, pageNumber: $_pageNum');
print("pageNum $_pageNum");
if (data.error == "0") { if (data != null && data.error == "0") {
_hasMoreData = true; if (data.accountList != null) {
_accountsList.addAll(data.accountList!); if (append) {
// Append with deduplication
_pageNum++; final existingIds = _accountsList.map((e) => e.id).toSet();
_isLoading = false; final newItems = data.accountList!
notifyListeners(); .where((item) => !existingIds.contains(item.id))
.toList();
_accountsList.addAll(newItems);
} else { } else {
_hasMoreData = false; _accountsList = data.accountList!;
}
// Check if we still have more records
_hasMoreData = data.accountList!.length >= 10;
if (_hasMoreData) _pageNum++;
}
}
} catch (e, s) {
debugPrint("Error in commonAccountListAPIFunction: $e");
} finally {
_isLoading = false; _isLoading = false;
notifyListeners(); notifyListeners();
} }
} }
} catch (e, s) {}
}
resetValues() { resetValues() {
print("rv"); print("rv");
......
...@@ -1120,8 +1120,26 @@ class Leadlistprovider extends ChangeNotifier { ...@@ -1120,8 +1120,26 @@ class Leadlistprovider extends ChangeNotifier {
} }
} }
bool _isLoadingMore = false;
bool get isLoadingMore => _isLoadingMore;
bool _hasMoreData = true;
bool get hasMoreData => _hasMoreData;
int _currentPage = 1;
String? _errorMessage;
String? get errorMessage => _errorMessage;
/// Reset pagination
void resetPagination() {
_currentPage = 1;
_hasMoreData = true;
_crmLeadList.clear();
notifyListeners();
}
Future<void> crmLeadListAPIFunction( Future<void> crmLeadListAPIFunction(
context, BuildContext context,
String? mode, String? mode,
String? leadStatus, String? leadStatus,
String? openStatus, String? openStatus,
...@@ -1129,13 +1147,21 @@ class Leadlistprovider extends ChangeNotifier { ...@@ -1129,13 +1147,21 @@ class Leadlistprovider extends ChangeNotifier {
String? referenceID, String? referenceID,
String? teamID, String? teamID,
String? segmentID, String? segmentID,
String? alphabet, String? alphabet, {
) async { bool append = false,
}) async {
try { try {
var HomeProv = Provider.of<HomescreenNotifier>(context, listen: false);
if (!append) {
_isLoading = true; _isLoading = true;
_crmLeadList.clear(); _errorMessage = null;
notifyListeners(); notifyListeners();
var HomeProv = Provider.of<HomescreenNotifier>(context, listen: false); } else {
_isLoadingMore = true;
notifyListeners();
}
final data = await ApiCalling.crmLeadListFilterSubmitAPI( final data = await ApiCalling.crmLeadListFilterSubmitAPI(
HomeProv.empId, HomeProv.empId,
HomeProv.session, HomeProv.session,
...@@ -1149,28 +1175,59 @@ class Leadlistprovider extends ChangeNotifier { ...@@ -1149,28 +1175,59 @@ class Leadlistprovider extends ChangeNotifier {
teamID, teamID,
segmentID, segmentID,
alphabet, alphabet,
_currentPage.toString(), //
); );
if (data != null) { debugPrint('empId: ${HomeProv.empId}, session: ${HomeProv.session}, pageNumber: $_currentPage');
_isLoading = true;
notifyListeners(); if (data != null && data.error == "0") {
if (data.error == "0") { if (append) {
_crmLeadList = data.leadList?.where((lead) => lead != null).toList() ?? []; _crmLeadList.addAll(data.leadList ?? []);
_isLoading = false;
checkDropDownValues();
notifyListeners();
} else { } else {
_isLoading = false; _crmLeadList = data.leadList ?? [];
notifyListeners(); }
if (data.leadList == null || data.leadList!.length < 10) {
_hasMoreData = false; // no more pages
} }
} else { } else {
_isLoading = false; if (!append) _errorMessage = "No leads found!";
notifyListeners(); _hasMoreData = false;
} }
} catch (e, s) { } catch (e, s) {
print('crmLeadListAPIFunction error: $e, stack: $s'); _errorMessage = "Error: $e";
}
_isLoading = false; _isLoading = false;
_isLoadingMore = false;
notifyListeners(); notifyListeners();
} }
/// Load next page
Future<void> loadMore(
BuildContext context,
String? mode,
String? leadStatus,
String? openStatus,
String? sourceID,
String? referenceID,
String? teamID,
String? segmentID,
String? alphabet,
) async {
if (_isLoadingMore || !_hasMoreData) return;
_currentPage++;
await crmLeadListAPIFunction(
context,
mode,
leadStatus,
openStatus,
sourceID,
referenceID,
teamID,
segmentID,
alphabet,
append: true,
);
} }
onChangedLeadId(String? value) { onChangedLeadId(String? value) {
......
...@@ -110,6 +110,7 @@ class ProspectListProvider extends ChangeNotifier { ...@@ -110,6 +110,7 @@ class ProspectListProvider extends ChangeNotifier {
employeeID, employeeID,
mobileNumberController.text, mobileNumberController.text,
companyNameController.text, companyNameController.text,
"1"
); );
if (data != null) { if (data != null) {
_isLoading = true; _isLoading = true;
......
...@@ -625,39 +625,88 @@ class Requestionlistprovider extends ChangeNotifier { ...@@ -625,39 +625,88 @@ class Requestionlistprovider extends ChangeNotifier {
} }
} }
int _pageNum = 1;
bool _hasMoreData = true;
bool _isLoadingMore = false;
bool get isLoadingMore => _isLoadingMore;
bool get hasMoreData => _hasMoreData;
int _currentPage = 1;
int get currentPage => _currentPage;
/// Reset before a fresh load (pull-to-refresh or filter change)
void resetPagination() {
_currentPage = 1;
_hasMoreData = true;
_requisitionList.clear();
notifyListeners();
}
Future<void> paymentRequestionListsAPIFunction( Future<void> paymentRequestionListsAPIFunction(
context, BuildContext context,
mode, String mode,
from, String from,
to, String to, {
) async { bool append = false,
}) async {
try { try {
var homeProvider = Provider.of<HomescreenNotifier>( var homeProvider = Provider.of<HomescreenNotifier>(
context, context,
listen: false, listen: false,
); );
if (!append) {
// reset for first page
_pageNum = 1;
_hasMoreData = true;
_requisitionList.clear(); _requisitionList.clear();
_isLoading = true; _isLoading = true;
} else {
_isLoadingMore = true;
}
notifyListeners(); notifyListeners();
final data = await ApiCalling.paymentRequestionListsAPI( final data = await ApiCalling.paymentRequestionListsAPI(
homeProvider.empId, homeProvider.empId,
homeProvider.session, homeProvider.session,
mode, mode,
from, from,
to, to,
_pageNum.toString(),
); );
if (data != null) { debugPrint('empId: ${homeProvider.empId}, session: ${homeProvider.session}, pageNumber: $_pageNum');
if (data.error == "0") {
_isLoading = false; if (data != null && data.error == "0") {
_requisitionList = data.requistionList!; if (append) {
} else if (data.error == "1") { final existingIds = _requisitionList.map((e) => e.id).toSet();
_isLoading = false; final newItems = data.requistionList!
.where((item) => !existingIds.contains(item.id))
.toList();
_requisitionList.addAll(newItems);
} else {
_requisitionList = data.requistionList ?? [];
}
// check if more data
if (data.requistionList == null || data.requistionList!.length < 10) {
_hasMoreData = false;
} else {
_pageNum++;
}
} else {
_hasMoreData = false;
} }
} catch (e) {
_hasMoreData = false;
} finally {
_isLoading = false;
_isLoadingMore = false;
notifyListeners(); notifyListeners();
} }
} catch (e, s) {}
} }
void showDatePickerDialog(BuildContext context) { void showDatePickerDialog(BuildContext context) {
showCupertinoModalPopup<void>( showCupertinoModalPopup<void>(
context: context, context: context,
......
...@@ -366,28 +366,80 @@ class Paymentreceiptsprovider extends ChangeNotifier { ...@@ -366,28 +366,80 @@ class Paymentreceiptsprovider extends ChangeNotifier {
} }
} }
Future<void> paymentsListAPI(context, from, to) async {
bool _isLoadingMore = false;
bool get isLoadingMore => _isLoadingMore;
bool _hasMoreData = true;
bool get hasMoreData => _hasMoreData;
int _currentPage = 1;
String? _errorMessage;
String? get errorMessage => _errorMessage;
/// Reset pagination
void resetPagination() {
_currentPage = 1;
_hasMoreData = true;
_receiptsList.clear();
notifyListeners();
}
Future<void> paymentsListAPI(
BuildContext context,
String from,
String to, {
bool append = false,
}) async {
try { try {
var prov = Provider.of<HomescreenNotifier>(context, listen: false); var prov = Provider.of<HomescreenNotifier>(context, listen: false);
if (!append) {
_isLoading = true; _isLoading = true;
_errorMessage = null;
notifyListeners(); notifyListeners();
} else {
_isLoadingMore = true;
notifyListeners();
}
final data = await ApiCalling.paymentRequisitionPaymentReceiptListAPI( final data = await ApiCalling.paymentRequisitionPaymentReceiptListAPI(
prov.empId, prov.empId,
prov.session, prov.session,
from, from,
to, to,
_currentPage.toString(),
); );
if (data != null) { debugPrint('empId: ${prov.empId}, session: ${prov.session}, pageNumber: $_currentPage');
if (data.error == "0") {
_receiptsList = data.receiptsList!; if (data != null && data.error == "0") {
_isLoading = false; if (append) {
notifyListeners(); _receiptsList.addAll(data.receiptsList ?? []);
} else if (data.error == "1") { } else {
_isLoading = false; _receiptsList = data.receiptsList ?? [];
}
if (data.receiptsList == null || data.receiptsList!.length < 10) {
_hasMoreData = false; // no more pages
}
} else {
if (!append) _errorMessage = "No receipts found!";
_hasMoreData = false;
}
} catch (e) {
_errorMessage = "Error: $e";
} }
_isLoading = false;
_isLoadingMore = false;
notifyListeners(); notifyListeners();
} }
} catch (e, s) {}
/// Load next page
Future<void> loadMore(BuildContext context, String from, String to) async {
if (_isLoadingMore || !_hasMoreData) return;
_currentPage++;
await paymentsListAPI(context, from, to, append: true);
} }
Future<void> paymentsListDetailsAPI(context, paymentId) async { Future<void> paymentsListDetailsAPI(context, paymentId) async {
......
...@@ -38,26 +38,79 @@ class Paymentrequisitionpaymentslistprovider extends ChangeNotifier{ ...@@ -38,26 +38,79 @@ class Paymentrequisitionpaymentslistprovider extends ChangeNotifier{
notifyListeners(); notifyListeners();
} }
Future<void> paymentsListAPI(context,from,to) async { bool _isLoadingMore = false;
try{ bool get isLoadingMore => _isLoadingMore;
var prov = Provider.of<HomescreenNotifier>(context,listen: false);
bool _hasMoreData = true;
bool get hasMoreData => _hasMoreData;
int _currentPage = 1;
String? _errorMessage;
String? get errorMessage => _errorMessage;
/// Reset pagination before new filter or refresh
void resetPagination() {
_currentPage = 1;
_hasMoreData = true;
_paymentsList.clear(); _paymentsList.clear();
notifyListeners();
}
Future<void> paymentsListAPI(
BuildContext context,
String from,
String to, {
bool append = false,
}) async {
try {
var prov = Provider.of<HomescreenNotifier>(context, listen: false);
if (!append) {
_isLoading = true; _isLoading = true;
_errorMessage = null;
notifyListeners(); notifyListeners();
final data = await ApiCalling.paymentRequisitionPaymentListAPI(prov.empId, prov.session,from,to); } else {
if(data!=null){ _isLoadingMore = true;
if(data.error=="0"){
_isLoading = false;
_paymentsList = data.paymentsList!;
notifyListeners(); notifyListeners();
}else if(data.error=="1"){
_isLoading = false;
} }
notifyListeners();
final data = await ApiCalling.paymentRequisitionPaymentListAPI(
prov.empId,
prov.session,
from,
to,
_currentPage.toString(), // pass page number
);
debugPrint('empId: ${prov.empId}, session: ${prov.session}, pageNumber: $_currentPage');
if (data != null && data.error == "0") {
if (append) {
_paymentsList.addAll(data.paymentsList ?? []);
} else {
_paymentsList = data.paymentsList ?? [];
} }
}catch(e,s){
if (data.paymentsList == null || data.paymentsList!.length < 10) {
_hasMoreData = false; // no more pages
}
} else {
if (!append) _errorMessage = "No data found!";
_hasMoreData = false;
} }
} catch (e) {
_errorMessage = "Error: $e";
}
_isLoading = false;
_isLoadingMore = false;
notifyListeners();
}
/// Load next page
Future<void> loadMore(BuildContext context, String from, String to) async {
if (_isLoadingMore || !_hasMoreData) return;
_currentPage++;
await paymentsListAPI(context, from, to, append: true);
} }
Future<void> paymentsListDetailsAPI(context,paymentId) async { Future<void> paymentsListDetailsAPI(context,paymentId) async {
......
...@@ -51,7 +51,8 @@ class TourExpensesProvider extends ChangeNotifier { ...@@ -51,7 +51,8 @@ class TourExpensesProvider extends ChangeNotifier {
} }
/// Fetch tour expenses list /// Fetch tour expenses list
Future<void> fetchTourExpenses(BuildContext context, String pageNumber) async { Future<void> fetchTourExpenses(BuildContext context, String pageNumber,
{bool append = false}) async {
_isLoading = true; _isLoading = true;
_errorMessage = null; _errorMessage = null;
notifyListeners(); notifyListeners();
...@@ -65,10 +66,22 @@ class TourExpensesProvider extends ChangeNotifier { ...@@ -65,10 +66,22 @@ class TourExpensesProvider extends ChangeNotifier {
pageNumber, pageNumber,
); );
debugPrint('empId: ${provider.empId}, session: ${provider.session}'); debugPrint(
'empId: ${provider.empId}, session: ${provider.session}, pageNumber: $pageNumber');
if (result != null) { if (result != null) {
if (append && _response != null && _response!.tourList != null) {
// Append with deduplication
final existingIds = _response!.tourList!.map((e) => e.id).toSet();
final newItems = (result.tourList ?? [])
.where((item) => !existingIds.contains(item.id))
.toList();
_response!.tourList!.addAll(newItems);
} else {
// First page or refresh
_response = result; _response = result;
}
} else { } else {
_errorMessage = "No data found!"; _errorMessage = "No data found!";
} }
...@@ -80,6 +93,8 @@ class TourExpensesProvider extends ChangeNotifier { ...@@ -80,6 +93,8 @@ class TourExpensesProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> fetchTourExpensesAddView(BuildContext context, String tourBillId) async { Future<void> fetchTourExpensesAddView(BuildContext context, String tourBillId) async {
_isLoading = true; _isLoading = true;
_errorMessage = null; _errorMessage = null;
......
...@@ -324,42 +324,112 @@ class Pagesdashboardprovider extends ChangeNotifier { ...@@ -324,42 +324,112 @@ class Pagesdashboardprovider extends ChangeNotifier {
} catch (e, s) {} } catch (e, s) {}
} }
bool _isLoadingMore = false;
bool get isLoadingMore => _isLoadingMore;
bool _hasMoreData = true;
bool get hasMoreData => _hasMoreData;
int _currentPage = 1;
String? _errorMessage;
String? get errorMessage => _errorMessage;
/// Reset everything
void resetPagination() {
_ordersList.clear();
_currentPage = 1;
_hasMoreData = true;
_isLoading = false;
_isLoadingMore = false;
_errorMessage = null;
notifyListeners();
}
Future<void> ordersListByModeAPIFunction( Future<void> ordersListByModeAPIFunction(
context, BuildContext context,
mode, String mode,
teamEmployee, String teamEmployee,
status, String status, {
) async { bool append = false,
}) async {
try { try {
var provider = Provider.of<HomescreenNotifier>(context, listen: false); var provider = Provider.of<HomescreenNotifier>(context, listen: false);
if (!append) {
_isLoading = true;
_errorMessage = null;
notifyListeners();
} else {
_isLoadingMore = true;
notifyListeners();
}
final data = await ApiCalling.ordersListByModeAPI( final data = await ApiCalling.ordersListByModeAPI(
provider.empId, provider.empId,
provider.session, provider.session,
mode, mode,
teamEmployee, teamEmployee,
status, status,
_currentPage.toString(),
); );
if (data != null) { debugPrint('empId: ${provider.empId}, session: ${provider.session}, pageNumber: $_currentPage');
_ordersList.clear();
_isLoading = true; if (data != null && data.error == "0") {
notifyListeners(); if (append) {
if (data.error == "0") { _ordersList.addAll(data.orderList ?? []);
_ordersList = data.orderList!; } else {
_isLoading = false; _ordersList = data.orderList ?? [];
if (_selectedEmployee != null && if (_selectedEmployee != null &&
!_employeesList.contains(_selectedEmployee)) { !_employeesList.contains(_selectedEmployee)) {
_selectedEmployee = null; _selectedEmployee = null;
_selectedEmpID = ""; _selectedEmpID = "";
_selectedEmpName = ""; _selectedEmpName = "";
} }
notifyListeners(); }
if (data.orderList == null || data.orderList!.length < 10) {
_hasMoreData = false;
}
} else { } else {
if (!append) _errorMessage = "No orders found!";
_hasMoreData = false;
}
} catch (e, s) {
_errorMessage = "Error: $e";
}
if (_selectedEmployee != null &&
!_employeesList.contains(_selectedEmployee)) {
_selectedEmployee = null;
_selectedEmpID = "";
_selectedEmpName = "";
}
_isLoading = false; _isLoading = false;
_isLoadingMore = false;
notifyListeners(); notifyListeners();
}
} }
} catch (e, s) {}
/// Load next page
Future<void> loadMore(
BuildContext context,
String mode,
String teamEmployee,
String status,
) async {
if (_isLoadingMore || !_hasMoreData) return;
_currentPage++;
await ordersListByModeAPIFunction(
context,
mode,
teamEmployee,
status,
append: true,
);
} }
Future<void> ordersDetailsByModeAPIFunction(context, orderId, mode) async { Future<void> ordersDetailsByModeAPIFunction(context, orderId, mode) async {
......
...@@ -120,40 +120,89 @@ class Paymentsprovider extends ChangeNotifier { ...@@ -120,40 +120,89 @@ class Paymentsprovider extends ChangeNotifier {
} catch (e, s) {} } catch (e, s) {}
} }
bool _isLoadingMore = false;
bool get isLoadingMore => _isLoadingMore;
bool _hasMoreData = true;
bool get hasMoreData => _hasMoreData;
int _currentPage = 1;
String? _errorMessage;
String? get errorMessage => _errorMessage;
void resetPagination() {
_paymentsList.clear();
_currentPage = 1;
_hasMoreData = true;
_isLoading = false;
_isLoadingMore = false;
_errorMessage = null;
notifyListeners();
}
Future<void> paymentsListsByModeAPIFunction( Future<void> paymentsListsByModeAPIFunction(
context, BuildContext context,
mode, String mode,
teamEmployee, String teamEmployee, {
) async { bool append = false,
}) async {
try { try {
var provider = Provider.of<HomescreenNotifier>(context, listen: false); var provider = Provider.of<HomescreenNotifier>(context, listen: false);
if (!append) {
_isLoading = true;
_errorMessage = null;
notifyListeners();
} else {
_isLoadingMore = true;
notifyListeners();
}
final data = await ApiCalling.paymentListsByModeAPI( final data = await ApiCalling.paymentListsByModeAPI(
provider.empId, provider.empId,
provider.session, provider.session,
mode, mode,
teamEmployee, teamEmployee,
_currentPage.toString(),
); );
if (data != null) { debugPrint('empId: ${provider.empId}, session: ${provider.session}, pageNumber: $_currentPage');
_paymentsList.clear();
_isLoading = true; if (data != null && data.error == "0") {
notifyListeners(); if (append) {
if (data.error == "0") { _paymentsList.addAll(data.orderList ?? []);
_paymentsList = data.orderList!; } else {
print(data.orderList!.length); _paymentsList = data.orderList ?? [];
_isLoading = false; }
if (_selectedEmployee != null &&
!_employeesList.contains(_selectedEmployee)) { if (data.orderList == null || data.orderList!.length < 10) {
_selectedEmployee = null; _hasMoreData = false;
_selectedEmpID = "";
_selectedEmpName = "";
} }
notifyListeners();
} else { } else {
_isLoading = false; if (!append) _errorMessage = "No payments found!";
_hasMoreData = false;
}
} catch (e, s) {
_errorMessage = "Error: $e";
} }
_isLoading = false;
_isLoadingMore = false;
notifyListeners(); notifyListeners();
} }
} catch (e, s) {}
Future<void> loadMore(
BuildContext context,
String mode,
String teamEmployee,
) async {
if (_isLoadingMore || !_hasMoreData) return;
_currentPage++;
await paymentsListsByModeAPIFunction(
context,
mode,
teamEmployee,
append: true,
);
} }
Future<void> paymentsDetailsByModeAPIFunction( Future<void> paymentsDetailsByModeAPIFunction(
......
...@@ -101,53 +101,139 @@ class Tpcagentsprovider extends ChangeNotifier{ ...@@ -101,53 +101,139 @@ class Tpcagentsprovider extends ChangeNotifier{
} }
Future<void> TPCAgentsListAPIFunction(context, mode,) async { bool _isLoadingMore = false;
bool get isLoadingMore => _isLoadingMore;
bool _hasMoreData = true;
bool get hasMoreData => _hasMoreData;
int _currentPage = 1;
String? _errorMessage;
String? get errorMessage => _errorMessage;
void resetPagination() {
_tpcAgentsList.clear();
_currentPage = 1;
_hasMoreData = true;
_isLoading = false;
_isLoadingMore = false;
_errorMessage = null;
notifyListeners();
}
Future<void> TPCAgentsListAPIFunction(
BuildContext context,
String mode, {
bool append = false,
}) async {
try { try {
var provider = Provider.of<HomescreenNotifier>(context, listen: false); var provider = Provider.of<HomescreenNotifier>(context, listen: false);
if (!append) {
_isLoading = true;
_errorMessage = null;
notifyListeners();
} else {
_isLoadingMore = true;
notifyListeners();
}
final data = await ApiCalling.TPCAgentListAPI( final data = await ApiCalling.TPCAgentListAPI(
provider.empId, provider.empId,
provider.session, provider.session,
mode, mode,
_currentPage.toString(), // page number
); );
if (data != null) { debugPrint('empId: ${provider.empId}, session: ${provider.session}, pageNumber: $_currentPage');
_tpcAgentsList.clear();
_isLoading = true; if (data != null && data.error == "0") {
notifyListeners(); if (append) {
if (data.error == "0") { _tpcAgentsList.addAll(data.tpcAgentList ?? []);
_tpcAgentsList = data.tpcAgentList!;
_isLoading = false;
} else { } else {
_isLoading = false; _tpcAgentsList = data.tpcAgentList ?? [];
} }
// stop if API returns less than page size
if (data.tpcAgentList == null || data.tpcAgentList!.length < 10) {
_hasMoreData = false;
}
} else {
if (!append) _errorMessage = "No agents found!";
_hasMoreData = false;
}
} catch (e, s) {
_errorMessage = "Error: $e";
}
_isLoading = false;
_isLoadingMore = false;
notifyListeners(); notifyListeners();
} }
} catch (e, s) {}
Future<void> loadMore(BuildContext context, String mode) async {
if (_isLoadingMore || !_hasMoreData) return;
_currentPage++;
await TPCAgentsListAPIFunction(context, mode, append: true);
} }
Future<void> TPCAgentsIssueListAPIFunction(context,) async {
Future<void> TPCAgentsIssueListAPIFunction(
BuildContext context, {
bool append = false,
}) async {
try { try {
var provider = Provider.of<HomescreenNotifier>(context, listen: false); var provider = Provider.of<HomescreenNotifier>(context, listen: false);
if (!append) {
_isLoading = true;
_errorMessage = null;
_currentPage = 1;
notifyListeners();
} else {
_isLoadingMore = true;
notifyListeners();
}
final data = await ApiCalling.pendingTPCAgentIssueListAPI( final data = await ApiCalling.pendingTPCAgentIssueListAPI(
provider.empId, provider.empId,
provider.session, provider.session,
_currentPage.toString(), // page number
); );
if (data != null) { debugPrint('empId: ${provider.empId}, session: ${provider.session}, pageNumber: $_currentPage');
_tpcAgentsIssueList.clear();
_isLoading = true;
notifyListeners();
if (data.error == "0") {
_tpcAgentsIssueList = data.pendingTpcIssueList!;
_isLoading = false;
notifyListeners(); if (data != null && data.error == "0") {
if (append) {
_tpcAgentsIssueList.addAll(data.pendingTpcIssueList ?? []);
} else { } else {
_isLoading = false; _tpcAgentsIssueList = data.pendingTpcIssueList ?? [];
}
// if API returns less than page size, stop loading more
if (data.pendingTpcIssueList == null ||
data.pendingTpcIssueList!.length < 10) {
_hasMoreData = false;
}
} else {
if (!append) _errorMessage = "No issues found!";
_hasMoreData = false;
} }
} catch (e) {
_errorMessage = "Error: $e";
}
_isLoading = false;
_isLoadingMore = false;
notifyListeners(); notifyListeners();
} }
} catch (e, s) {}
Future<void> loadMoreIssues(BuildContext context) async {
if (_isLoadingMore || !_hasMoreData) return;
_currentPage++;
await TPCAgentsIssueListAPIFunction(context, append: true);
} }
Future<void> TPCAgentsDetailsAPIFunction(context, tpc_agent_id) async { Future<void> TPCAgentsDetailsAPIFunction(context, tpc_agent_id) async {
try { try {
var provider = Provider.of<HomescreenNotifier>(context, listen: false); var provider = Provider.of<HomescreenNotifier>(context, listen: false);
......
...@@ -7,7 +7,7 @@ class AppColors { ...@@ -7,7 +7,7 @@ class AppColors {
static Color greenish = Color(0xFF00BC57); static Color greenish = Color(0xFF00BC57);
static Color grey_semi = Color(0xFF999999); static Color grey_semi = Color(0xFF999999);
static Color grey_thick = Color(0xFF818181); static Color grey_thick = Color(0xFF818181);
static Color red = Color (0xFFFF0000); static Color red = Color(0xFFFF0000);
static Color thick_navy_blue = Color(0xff023047); static Color thick_navy_blue = Color(0xff023047);
static Color cyan_blue = Color(0xFF219EBC); static Color cyan_blue = Color(0xFF219EBC);
static Color profile_card_gradient1 = Color(0xFFCFEEFF); static Color profile_card_gradient1 = Color(0xFFCFEEFF);
...@@ -26,5 +26,5 @@ class AppColors { ...@@ -26,5 +26,5 @@ class AppColors {
static Color requested_bg_color = Color(0xFFE6F6FF); static Color requested_bg_color = Color(0xFFE6F6FF);
static Color rejected_bg_color = Color(0xFFFFF5F5); static Color rejected_bg_color = Color(0xFFFFF5F5);
static Color approved_bg_color = Color(0xFFE9FFE8); static Color approved_bg_color = Color(0xFFE9FFE8);
static Color processed_bg_color = Color(0xFFEFFF8E5); static Color processed_bg_color = Color(0xffefff8e5);
} }
...@@ -18,8 +18,9 @@ import 'WebSocketManager.dart'; ...@@ -18,8 +18,9 @@ import 'WebSocketManager.dart';
class BackgroundLocation { class BackgroundLocation {
// The channel to be used for communication. // The channel to be used for communication.
// This channel is also refrenced inside both iOS and Abdroid classes // This channel is also refrenced inside both iOS and Abdroid classes
static const MethodChannel _channel = static const MethodChannel _channel = MethodChannel(
MethodChannel('com.almoullim.background_location/methods'); 'com.almoullim.background_location/methods',
);
static Timer? _locationTimer; static Timer? _locationTimer;
static get context => null; static get context => null;
...@@ -57,7 +58,8 @@ class BackgroundLocation { ...@@ -57,7 +58,8 @@ class BackgroundLocation {
requestAlertPermission: false, requestAlertPermission: false,
requestBadgePermission: false, requestBadgePermission: false,
requestSoundPermission: false, requestSoundPermission: false,
)); ),
);
await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings);
// Disable sound for the default notification channel // Disable sound for the default notification channel
...@@ -71,7 +73,8 @@ class BackgroundLocation { ...@@ -71,7 +73,8 @@ class BackgroundLocation {
); );
await flutterLocalNotificationsPlugin await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation< .resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>() AndroidFlutterLocalNotificationsPlugin
>()
?.createNotificationChannel(androidChannel); ?.createNotificationChannel(androidChannel);
// print("Flutter Local Notifications initialized successfully."); // print("Flutter Local Notifications initialized successfully.");
...@@ -87,9 +90,10 @@ class BackgroundLocation { ...@@ -87,9 +90,10 @@ class BackgroundLocation {
// Check if location services are enabled // Check if location services are enabled
isLocationEnabled = await Geolocator.isLocationServiceEnabled(); isLocationEnabled = await Geolocator.isLocationServiceEnabled();
// Check if the app has been granted location permission // Check if the app has been granted location permission
LocationPermission permission = await Geolocator.checkPermission(); LocationPermission permission = await Geolocator.checkPermission();
hasLocationPermission = permission == LocationPermission.always || hasLocationPermission =
permission == LocationPermission.always ||
permission == LocationPermission.whileInUse; permission == LocationPermission.whileInUse;
final loc.Location location = loc.Location(); final loc.Location location = loc.Location();
...@@ -131,12 +135,14 @@ class BackgroundLocation { ...@@ -131,12 +135,14 @@ class BackgroundLocation {
const NotificationDetails platformChannelSpecifics = NotificationDetails( const NotificationDetails platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics, android: androidPlatformChannelSpecifics,
iOS: darwinNotificationDetails); iOS: darwinNotificationDetails,
);
// Check if the notification with the same ID is already being shown // Check if the notification with the same ID is already being shown
final List<PendingNotificationRequest> pendingNotifications = final List<PendingNotificationRequest> pendingNotifications =
await flutterLocalNotificationsPlugin.pendingNotificationRequests(); await flutterLocalNotificationsPlugin.pendingNotificationRequests();
final notificationAlreadyExists = pendingNotifications final notificationAlreadyExists = pendingNotifications.any(
.any((notification) => notification.id == notificationId); (notification) => notification.id == notificationId,
);
// If notification already exists, update it; otherwise, show a new one // If notification already exists, update it; otherwise, show a new one
if (notificationAlreadyExists) { if (notificationAlreadyExists) {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
...@@ -209,14 +215,18 @@ class BackgroundLocation { ...@@ -209,14 +215,18 @@ class BackgroundLocation {
// Notify user to enable GPS // Notify user to enable GPS
checkAndRequestLocationPermissions(); checkAndRequestLocationPermissions();
showNotification( showNotification(
"GEN ERP", "You're Offline !, Check your GPS connection."); "GEN ERP",
"You're Offline !, Check your GPS connection.",
);
// print( // print(
// 'GPS is not enabled. Please enable GPS to start the location service.'); // 'GPS is not enabled. Please enable GPS to start the location service.');
} }
if (!isNetworkAvailable) { if (!isNetworkAvailable) {
// Notify user to connect to a network // Notify user to connect to a network
showNotification( showNotification(
"GEN ERP", "You're Offline !, Check your network connection."); "GEN ERP",
"You're Offline !, Check your network connection.",
);
// print( // print(
// 'Network is not available. Please connect to a network to start the location service.'); // 'Network is not available. Please connect to a network to start the location service.');
} }
...@@ -266,16 +276,16 @@ class BackgroundLocation { ...@@ -266,16 +276,16 @@ class BackgroundLocation {
saveLastLocationTime(); saveLastLocationTime();
var completer = Completer<Location>(); var completer = Completer<Location>();
var _location = Location(); var location = Location();
await getLocationUpdates((location) { await getLocationUpdates((location) {
_location.latitude = location.latitude; location.latitude = location.latitude;
_location.longitude = location.longitude; location.longitude = location.longitude;
_location.accuracy = location.accuracy; location.accuracy = location.accuracy;
_location.altitude = location.altitude; location.altitude = location.altitude;
_location.bearing = location.bearing; location.bearing = location.bearing;
_location.speed = location.speed; location.speed = location.speed;
_location.time = location.time; location.time = location.time;
completer.complete(_location); completer.complete(location);
}); });
return completer.future; return completer.future;
...@@ -300,12 +310,14 @@ class BackgroundLocation { ...@@ -300,12 +310,14 @@ class BackgroundLocation {
bearing: locationData['bearing'], bearing: locationData['bearing'],
speed: locationData['speed'], speed: locationData['speed'],
time: locationData['time'], time: locationData['time'],
isMock: locationData['is_mock']), isMock: locationData['is_mock'],
),
); );
//Send location updates using WebSocketManager //Send location updates using WebSocketManager
if (await webSocketManager.isNetworkAvailable()) { if (await webSocketManager.isNetworkAvailable()) {
webSocketManager.sendMessage(jsonEncode({ webSocketManager.sendMessage(
jsonEncode({
"command": "server_request", "command": "server_request",
"route": "attendenece_live_location_update", "route": "attendenece_live_location_update",
"session_id": sessionId, "session_id": sessionId,
...@@ -321,8 +333,9 @@ class BackgroundLocation { ...@@ -321,8 +333,9 @@ class BackgroundLocation {
"speed_accuracy": locationData['speedAccuracyMetersPerSecond'], "speed_accuracy": locationData['speedAccuracyMetersPerSecond'],
"location_accuracy": locationData['accuracy'], "location_accuracy": locationData['accuracy'],
"location_provider": "", "location_provider": "",
} },
})); }),
);
// print("Hello GENERP! You're Online!"); // print("Hello GENERP! You're Online!");
showNotification("GEN ERP", "You're Online!"); showNotification("GEN ERP", "You're Online!");
} else { } else {
...@@ -438,15 +451,16 @@ class Location { ...@@ -438,15 +451,16 @@ class Location {
double? time; double? time;
bool? isMock; bool? isMock;
Location( Location({
{@required this.longitude, @required this.longitude,
@required this.latitude, @required this.latitude,
@required this.altitude, @required this.altitude,
@required this.accuracy, @required this.accuracy,
@required this.bearing, @required this.bearing,
@required this.speed, @required this.speed,
@required this.time, @required this.time,
@required this.isMock}); @required this.isMock,
});
toMap() { toMap() {
var obj = { var obj = {
...@@ -457,7 +471,7 @@ class Location { ...@@ -457,7 +471,7 @@ class Location {
'accuracy': accuracy, 'accuracy': accuracy,
'speed': speed, 'speed': speed,
'time': time, 'time': time,
'is_mock': isMock 'is_mock': isMock,
}; };
return obj; return obj;
} }
......
...@@ -42,7 +42,7 @@ PreferredSizeWidget appbar(BuildContext context, title) { ...@@ -42,7 +42,7 @@ PreferredSizeWidget appbar(BuildContext context, title) {
); );
} }
PreferredSizeWidget appbarNew(BuildContext context, title,int color) { PreferredSizeWidget appbarNew(BuildContext context, title, int color) {
return AppBar( return AppBar(
backgroundColor: Color(color), backgroundColor: Color(color),
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
...@@ -53,9 +53,12 @@ PreferredSizeWidget appbarNew(BuildContext context, title,int color) { ...@@ -53,9 +53,12 @@ PreferredSizeWidget appbarNew(BuildContext context, title,int color) {
children: [ children: [
InkResponse( InkResponse(
onTap: () => Navigator.pop(context, true), onTap: () => Navigator.pop(context, true),
child: SvgPicture.asset("assets/svg/appbar_back_button.svg", height: 25), child: SvgPicture.asset(
"assets/svg/appbar_back_button.svg",
height: 25,
), ),
SizedBox(width: 10,), ),
SizedBox(width: 10),
InkResponse( InkResponse(
onTap: () => Navigator.pop(context, true), onTap: () => Navigator.pop(context, true),
child: Text( child: Text(
...@@ -128,7 +131,13 @@ PreferredSizeWidget appbar2(BuildContext context, title, reset, widget) { ...@@ -128,7 +131,13 @@ PreferredSizeWidget appbar2(BuildContext context, title, reset, widget) {
); );
} }
PreferredSizeWidget appbar2New(BuildContext context, title, reset, widget,int color) { PreferredSizeWidget appbar2New(
BuildContext context,
title,
reset,
widget,
int color,
) {
return AppBar( return AppBar(
backgroundColor: Color(color), backgroundColor: Color(color),
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
...@@ -141,22 +150,23 @@ PreferredSizeWidget appbar2New(BuildContext context, title, reset, widget,int co ...@@ -141,22 +150,23 @@ PreferredSizeWidget appbar2New(BuildContext context, title, reset, widget,int co
InkResponse( InkResponse(
onTap: () { onTap: () {
HapticFeedback.selectionClick(); HapticFeedback.selectionClick();
if(reset!=null){ if (reset != null) {
reset(); reset();
} }
Navigator.pop(context, true); Navigator.pop(context, true);
}, },
child: SvgPicture.asset("assets/svg/appbar_back_button.svg", height: 25), child: SvgPicture.asset(
"assets/svg/appbar_back_button.svg",
height: 25,
),
), ),
SizedBox(width: 10,), SizedBox(width: 10),
Expanded( Expanded(
flex: 4, flex: 4,
child: InkResponse( child: InkResponse(
onTap: () { onTap: () {
HapticFeedback.selectionClick(); HapticFeedback.selectionClick();
if(reset!=null){ if (reset != null) {
reset(); reset();
} }
Navigator.pop(context, true); Navigator.pop(context, true);
...@@ -207,10 +217,11 @@ Widget TextWidget(context, text) { ...@@ -207,10 +217,11 @@ Widget TextWidget(context, text) {
} }
Widget errorWidget(context, text) { Widget errorWidget(context, text) {
if (text != null) if (text != null) {
return Text(text!, style: TextStyle(color: Colors.red, fontSize: 12)); return Text(text!, style: TextStyle(color: Colors.red, fontSize: 12));
else } else {
return SizedBox(height: 10); return SizedBox(height: 10);
}
} }
Widget textControllerWidget( Widget textControllerWidget(
...@@ -230,14 +241,17 @@ Widget textControllerWidget( ...@@ -230,14 +241,17 @@ Widget textControllerWidget(
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if(textHead!="")...[ if (textHead != "") ...[
Padding( Padding(
padding: const EdgeInsets.only(bottom: 5.0, top: 8.0), padding: const EdgeInsets.only(bottom: 5.0, top: 8.0),
child: Text(textHead), child: Text(textHead),
), ),
], ],
Container( Container(
height: hintText == "Enter Description" || hintText=="Write Feedback" ? 150 : 50, height:
hintText == "Enter Description" || hintText == "Write Feedback"
? 150
: 50,
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
color: readonly ? Color(0xFFD7D7D7) : AppColors.text_field_color, color: readonly ? Color(0xFFD7D7D7) : AppColors.text_field_color,
...@@ -250,7 +264,10 @@ Widget textControllerWidget( ...@@ -250,7 +264,10 @@ Widget textControllerWidget(
controller: controller, controller: controller,
readOnly: readonly, readOnly: readonly,
keyboardType: inputtype, keyboardType: inputtype,
maxLines: hintText == "Enter Description" || hintText=="Write Feedback" ? 60 : 1, maxLines:
hintText == "Enter Description" || hintText == "Write Feedback"
? 60
: 1,
onChanged: onChanged, onChanged: onChanged,
focusNode: focusNode, focusNode: focusNode,
onTapUpOutside: (event) { onTapUpOutside: (event) {
...@@ -415,6 +432,6 @@ class MyNavigatorObserver extends NavigatorObserver { ...@@ -415,6 +432,6 @@ class MyNavigatorObserver extends NavigatorObserver {
routeSettingName = route.settings.name.toString(); routeSettingName = route.settings.name.toString();
// Called when a route has been popped off the navigator. // Called when a route has been popped off the navigator.
print('Route popped: ${route.settings.name}'); print('Route popped: ${route.settings.name}');
print('didPopped: ${didPopped}'); print('didPopped: $didPopped');
} }
} }
...@@ -32,13 +32,12 @@ class Dropdowntheme { ...@@ -32,13 +32,12 @@ class Dropdowntheme {
), ),
scrollbarTheme: ScrollbarThemeData( scrollbarTheme: ScrollbarThemeData(
radius: const Radius.circular(15), radius: const Radius.circular(15),
thickness: MaterialStateProperty.all<double>(6), thickness: WidgetStateProperty.all<double>(6),
thumbVisibility: MaterialStateProperty.all<bool>(true), thumbVisibility: WidgetStateProperty.all<bool>(true),
), ),
); );
final menuItemStyleData = const MenuItemStyleData( final menuItemStyleData = const MenuItemStyleData(
height: 40, height: 40,
padding: EdgeInsets.only(left: 14, right: 14), padding: EdgeInsets.only(left: 14, right: 14),
); );
} }
This diff is collapsed.
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_svg/svg.dart';
import '../../Utils/app_colors.dart';
class JobDescriptionScreen extends StatefulWidget {
final String htmlData;
final String title;
final String designation;
const JobDescriptionScreen({
Key? key,
required this.htmlData,
this.title = "Job Description",
required this.designation,
}) : super(key: key);
@override
State<JobDescriptionScreen> createState() => _JobDescriptionScreenState();
}
class _JobDescriptionScreenState extends State<JobDescriptionScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.scaffold_bg_color,
/// AppBar
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
title: Row(
children: [
InkResponse(
onTap: () => Navigator.pop(context, true),
child: SvgPicture.asset(
"assets/svg/appbar_back_button.svg",
height: 25,
),
),
const SizedBox(width: 10),
Text(
"Job Description",
style: TextStyle(
fontSize: 18,
fontFamily: "Plus Jakarta Sans",
fontWeight: FontWeight.w600,
color: AppColors.semi_black,
),
),
],
),
),
/// Body
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 18),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/// Designation Heading
Text(
widget.designation,
style: TextStyle(
color: AppColors.app_blue,
fontFamily: "JakartaSemiBold",
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 12),
/// HTML Description
Html(
data: widget.htmlData,
style: {
"h2": Style(
wordSpacing: 0,
letterSpacing: 0,
fontSize: FontSize(16),
fontFamily: "JakartaMedium",
color: AppColors.semi_black,
),
"h3": Style(
wordSpacing: 0,
letterSpacing: 0,
fontSize: FontSize(12),
fontFamily: "JakartaMedium",
color: AppColors.semi_black,
),
"p": Style(
wordSpacing: 0,
letterSpacing: 0,
fontSize: FontSize(12),
fontFamily: "JakartaMedium",
color: AppColors.grey_semi,
lineHeight: LineHeight.number(2.4),
),
"ul": Style(
wordSpacing: 0,
letterSpacing: 0,
fontSize: FontSize(15),
fontFamily: "JakartaMedium",
color: AppColors.grey_semi,
padding: HtmlPaddings.only(left: 12, right: 8),
lineHeight: LineHeight.number(1.4),
),
"li": Style(
wordSpacing: 0,
letterSpacing: 0,
fontSize: FontSize(14),
fontFamily: "JakartaMedium",
color: Colors.black,
padding: HtmlPaddings.only(left: 4),
lineHeight: LineHeight.number(1.4),
margin: Margins.only(bottom: 10),
),
"a": Style(
color: Colors.blue,
textDecoration: TextDecoration.underline,
),
},
onLinkTap: (url, _, __) {
debugPrint("Link tapped: $url");
if (url != null) {
// launchUrl(Uri.parse(url)); //
}
},
),
],
),
),
),
);
}
}
...@@ -27,15 +27,13 @@ Future main() async { ...@@ -27,15 +27,13 @@ Future main() async {
class WebERPIOS extends StatefulWidget { class WebERPIOS extends StatefulWidget {
final String url; final String url;
const WebERPIOS({Key? key, required this.url}) : super(key: key); const WebERPIOS({super.key, required this.url});
@override @override
State<WebERPIOS> createState() => _WebERPIOSState(); State<WebERPIOS> createState() => _WebERPIOSState();
} }
class _WebERPIOSState extends State<WebERPIOS> { class _WebERPIOSState extends State<WebERPIOS> {
Map _source = {ConnectivityResult.mobile: true}; Map _source = {ConnectivityResult.mobile: true};
final MyConnectivity _connectivity = MyConnectivity.instance; final MyConnectivity _connectivity = MyConnectivity.instance;
...@@ -100,12 +98,18 @@ class _WebERPIOSState extends State<WebERPIOS> { ...@@ -100,12 +98,18 @@ class _WebERPIOSState extends State<WebERPIOS> {
default: default:
connection = 'Offline'; connection = 'Offline';
} }
return connection=="Online"?Platform.isAndroid return connection == "Online"
? Platform.isAndroid
? WillPopScope( ? WillPopScope(
onWillPop: () => onBackPressed(context), onWillPop: () => onBackPressed(context),
child: SafeArea(top: false, bottom: true, child: _scaffold(context)), child: SafeArea(
top: false,
bottom: true,
child: _scaffold(context),
),
) )
: _scaffold(context):NoNetwork(context); : _scaffold(context)
: NoNetwork(context);
} }
Widget _scaffold(BuildContext context) { Widget _scaffold(BuildContext context) {
......
...@@ -19,52 +19,88 @@ class Accountslist extends StatefulWidget { ...@@ -19,52 +19,88 @@ class Accountslist extends StatefulWidget {
} }
class _AccountslistState extends State<Accountslist> { class _AccountslistState extends State<Accountslist> {
ScrollController scrollController = ScrollController(); final ScrollController _scrollController = ScrollController();
FocusNode focusNode1 = FocusNode(); int _currentPage = 1;
FocusNode focusNode2 = FocusNode(); bool _isLoadingMore = false;
bool _hasMoreItems = true;
Map _source = {ConnectivityResult.mobile: true}; Map _source = {ConnectivityResult.mobile: true};
final MyConnectivity _connectivity = MyConnectivity.instance; final MyConnectivity _connectivity = MyConnectivity.instance;
@override @override
void initState() { void initState() {
// TODO: implement initState
super.initState(); super.initState();
_connectivity.initialise(); _connectivity.initialise();
_connectivity.myStream.listen((source) { _connectivity.myStream.listen((source) {
setState(() => _source = source); setState(() => _source = source);
}); });
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
var provider = Provider.of<Accountslistprovider>(context, listen: false); _scrollController.addListener(_scrollListener);
provider.commonAccountListAPIFunction(context);
provider.pageNum = 1; // fetch first page once
provider.commonAccountListAPIFunction(context); Future.microtask(() {
// if (scrollController.position.maxScrollExtent == final provider =
// scrollController.offset) { Provider.of<Accountslistprovider>(context, listen: false);
scrollController.addListener(() {
if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent * 0.9 &&
!provider.isLoading &&
provider.hasMoreData) {
provider.commonAccountListAPIFunction(context); provider.commonAccountListAPIFunction(context);
}
});
}); });
} }
@override @override
void dispose() { void dispose() {
// TODO: implement dispose _scrollController.removeListener(_scrollListener);
super.dispose(); _scrollController.dispose();
scrollController.dispose();
_connectivity.disposeStream(); _connectivity.disposeStream();
super.dispose();
}
void _scrollListener() {
if (_scrollController.position.pixels >=
_scrollController.position.maxScrollExtent) {
_loadMoreItems(context);
}
}
void _loadMoreItems(BuildContext context) {
if (_isLoadingMore || !_hasMoreItems) return;
final provider = Provider.of<Accountslistprovider>(context, listen: false);
setState(() {
_isLoadingMore = true;
_currentPage++;
});
provider.commonAccountListAPIFunction(context, append: true).then((_) {
setState(() {
_isLoadingMore = false;
final newItems = provider.accountsList;
if (newItems.length < _currentPage * 15) {
//api gives 15 records
_hasMoreItems = false;
}
});
}).catchError((_) {
setState(() {
_isLoadingMore = false;
_currentPage--; // rollback
});
});
}
void _refreshList(BuildContext context) {
final provider = Provider.of<Accountslistprovider>(context, listen: false);
setState(() {
_currentPage = 1;
_hasMoreItems = true;
_isLoadingMore = false;
});
provider.commonAccountListAPIFunction(context);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
switch (_source.keys.toList()[0]) { switch (_source.keys.toList()[0]) {
case ConnectivityResult.mobile: case ConnectivityResult.mobile:
connection = 'Online';
break;
case ConnectivityResult.wifi: case ConnectivityResult.wifi:
connection = 'Online'; connection = 'Online';
break; break;
...@@ -72,6 +108,7 @@ class _AccountslistState extends State<Accountslist> { ...@@ -72,6 +108,7 @@ class _AccountslistState extends State<Accountslist> {
default: default:
connection = 'Offline'; connection = 'Offline';
} }
return (connection == "Online") return (connection == "Online")
? Platform.isAndroid ? Platform.isAndroid
? WillPopScope( ? WillPopScope(
...@@ -86,12 +123,21 @@ class _AccountslistState extends State<Accountslist> { ...@@ -86,12 +123,21 @@ class _AccountslistState extends State<Accountslist> {
: NoNetwork(context); : NoNetwork(context);
} }
@override
Widget _scaffold(BuildContext context) { Widget _scaffold(BuildContext context) {
return Consumer<Accountslistprovider>( return Consumer<Accountslistprovider>(
builder: (context, provider, child) { builder: (context, provider, child) {
var accountList = provider.accountsList; final accountList = provider.accountsList;
print(accountList.length);
if (provider.isLoading && _currentPage == 1) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
if (accountList.isEmpty) {
return Scaffold(body: Emptywidget(context));
}
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
appBar: appbar2New( appBar: appbar2New(
...@@ -99,66 +145,44 @@ class _AccountslistState extends State<Accountslist> { ...@@ -99,66 +145,44 @@ class _AccountslistState extends State<Accountslist> {
"Account List", "Account List",
provider.resetValues, provider.resetValues,
Container( Container(
padding: EdgeInsets.symmetric(horizontal: 5, vertical: 5), padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
child: InkResponse( child: InkResponse(
onTap: () { onTap: () {
_showFilterSheet1(context); _showFilterSheet1(context);
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: SvgPicture.asset("assets/svg/filter_ic.svg", height: 18), child:
SvgPicture.asset("assets/svg/filter_ic.svg", height: 18),
), ),
), ),
), ),
0xFFFFFFFF 0xFFFFFFFF,
), ),
backgroundColor: AppColors.scaffold_bg_color, backgroundColor: AppColors.scaffold_bg_color,
body: body: RefreshIndicator(
provider.isLoading onRefresh: () async => _refreshList(context),
? Center( child: ListView.builder(
child: CircularProgressIndicator( controller: _scrollController,
valueColor: AlwaysStoppedAnimation(AppColors.app_blue), padding: const EdgeInsets.all(12),
), itemCount: accountList.length + (_hasMoreItems ? 1 : 0),
)
: accountList.isNotEmpty
? SizedBox(
child: Scrollbar(
child: SingleChildScrollView(
controller: scrollController,
child: Column(
children: [
ListView.builder(
itemCount:
accountList.length +
(provider.hasMoreData && provider.isLoading
? 1
: 0),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) { itemBuilder: (context, index) {
if (accountList.isEmpty) { if (index >= accountList.length) {
return SizedBox(
child: Center(
child: Text("No Data Available"),
),
);
}
if (index == accountList.length &&
!provider.isLoading) {
return Padding( return Padding(
padding: EdgeInsets.all(8.0), padding: const EdgeInsets.symmetric(vertical: 16),
child: Center( child: Center(
child: CircularProgressIndicator.adaptive( child: _isLoadingMore
valueColor: ? const CircularProgressIndicator(
AlwaysStoppedAnimation<Color>( color: Colors.blue,
AppColors.app_blue, )
), : !_hasMoreItems
), ? const Text("No more accounts to load")
: const SizedBox.shrink(),
), ),
); );
} }
final account = accountList[index];
return InkResponse( return InkResponse(
onTap: () async { onTap: () async {
print( print(
...@@ -260,132 +284,11 @@ class _AccountslistState extends State<Accountslist> { ...@@ -260,132 +284,11 @@ class _AccountslistState extends State<Accountslist> {
); );
}, },
), ),
],
),
),
),
)
: Emptywidget(context),
);
},
);
}
Future<void> _showFilterSheet(BuildContext context) {
return showModalBottomSheet(
useSafeArea: true,
isDismissible: true,
isScrollControlled: true,
showDragHandle: true,
backgroundColor: Colors.white,
enableDrag: true,
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return SafeArea(
child: Consumer<Accountslistprovider>(
builder: (context, provider, child) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
margin: EdgeInsets.only(
bottom: 15,
left: 15,
right: 15,
top: 10,
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: Text(
"Filter",
style: TextStyle(
color: AppColors.app_blue,
fontSize: 16,
fontFamily: "JakartaMedium",
),
),
),
textControllerWidget(
context,
provider.companyNameController,
"Company Name",
"Enter Company Name",
(p0) {},
TextInputType.text,
false,
null,
focusNode1,
focusNode2,
TextInputAction.next,
),
textControllerWidget(
context,
provider.mobileNumberController,
"Mobile Number",
"Enter Mobile Number",
(p0) {},
TextInputType.number,
false,
FilteringTextInputFormatter.digitsOnly,
focusNode2,
null,
TextInputAction.done,
10,
),
InkResponse(
onTap: () {
Navigator.pop(context);
provider.pageNum = 1;
provider.commonAccountListAPIFunction(context);
provider.companyNameController.clear();
provider.mobileNumberController.clear();
},
child: Container(
height: 45,
alignment: Alignment.center,
margin: EdgeInsets.symmetric(
horizontal: 10,
vertical: 15,
),
padding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 5,
),
decoration: BoxDecoration(
color: AppColors.app_blue,
borderRadius: BorderRadius.circular(15),
),
child: Text(
"Search",
style: TextStyle(
fontSize: 15,
fontFamily: "JakartaMedium",
color: Colors.white,
),
),
),
),
],
),
), ),
); );
}, },
),
);
},
);
},
); );
} }
Future<void> _showFilterSheet1(BuildContext context) { Future<void> _showFilterSheet1(BuildContext context) {
List<bool> isSelected = List.generate( List<bool> isSelected = List.generate(
2, 2,
...@@ -617,14 +520,9 @@ class _AccountslistState extends State<Accountslist> { ...@@ -617,14 +520,9 @@ class _AccountslistState extends State<Accountslist> {
}, },
); );
} }
Future<bool> _onBackPressed(BuildContext context) async {
Provider.of<Accountslistprovider>(context, listen: false).pageNum = 1;
Navigator.pop(context, true);
return true;
}
} }
// Divider( // Divider(
// thickness: 0.5, // thickness: 0.5,
// color: Color(0xFFD7D7D7), // color: Color(0xFFD7D7D7),
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment