Merge branch 'development_sikander' of https://gitlab.com/mirza.shafique/mohem_flutter_app into development_sultan

merge-requests/1/merge
Sultan Khan 4 years ago
commit 2f395f29df

@ -5,6 +5,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:http/io_client.dart'; import 'package:http/io_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/exceptions/api_exception.dart'; import 'package:mohem_flutter_app/exceptions/api_exception.dart';
import '../main.dart'; import '../main.dart';
@ -81,6 +82,9 @@ class ApiClient {
logger.i("res: " + response.body); logger.i("res: " + response.body);
} }
var jsonData = jsonDecode(response.body); var jsonData = jsonDecode(response.body);
if (jsonData["IsAuthenticated"] != null) {
AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
}
if (jsonData["ErrorMessage"] == null) { if (jsonData["ErrorMessage"] == null) {
return factoryConstructor(jsonData); return factoryConstructor(jsonData);
} else { } else {
@ -237,4 +241,4 @@ class ApiClient {
} }
Future<Response> _post(url, {Map<String, String>? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding)); Future<Response> _post(url, {Map<String, String>? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding));
} }

@ -79,7 +79,7 @@ class LoginApiClient {
Future<GenericResponseModel?> checkActivationCode(bool isDeviceNFC, String? mobileNumber, String activationCode, String? pUserName) async { Future<GenericResponseModel?> checkActivationCode(bool isDeviceNFC, String? mobileNumber, String activationCode, String? pUserName) async {
String url = "${ApiConsts.erpRest}CheckActivationCode"; String url = "${ApiConsts.erpRest}CheckActivationCode";
Map<String, dynamic> postParams = {"isDeviceNFC": isDeviceNFC, "MobileNumber": mobileNumber, "activationCode": activationCode, "P_USER_NAME": pUserName}; Map<String, dynamic> postParams = {"IsDeviceNFC": isDeviceNFC, "MobileNumber": mobileNumber, "activationCode": activationCode, "P_USER_NAME": pUserName};
postParams.addAll(AppState().postParamsJson); postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) { return await ApiClient().postJsonForObject((json) {
GenericResponseModel responseData = GenericResponseModel.fromJson(json); GenericResponseModel responseData = GenericResponseModel.fromJson(json);

@ -12,6 +12,10 @@ class AppState {
factory AppState() => _instance; factory AppState() => _instance;
bool isAuthenticated = false;
set setIsAuthenticated(v) => isAuthenticated = v;
bool isLogged = false; bool isLogged = false;
set setLogged(v) => isLogged = v; set setLogged(v) => isLogged = v;

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/config/routes.dart';
// import 'package:fluttertoast/fluttertoast.dart'; // import 'package:fluttertoast/fluttertoast.dart';
@ -83,12 +84,12 @@ class Utils {
if (onErrorMessage != null) { if (onErrorMessage != null) {
onErrorMessage(errorMessage); onErrorMessage(errorMessage);
} else { } else {
if (errorMessage.contains("User session is not valid")) { if (!AppState().isAuthenticated) {
showDialog( showDialog(
context: cxt, context: cxt,
builder: (cxt) => ConfirmDialog( builder: (cxt) => ConfirmDialog(
message: errorMessage, message: errorMessage,
onTap: (){ onTap: () {
Navigator.pushNamedAndRemoveUntil(cxt, AppRoutes.login, (Route<dynamic> route) => false); Navigator.pushNamedAndRemoveUntil(cxt, AppRoutes.login, (Route<dynamic> route) => false);
}, },
), ),

@ -226,3 +226,4 @@ class OtpDialog {
// } // }
} }
} }

@ -36,7 +36,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
data.fetchWorkListCounter(context); data.fetchWorkListCounter(context);
data.fetchMissingSwipe(context); data.fetchMissingSwipe(context);
data.fetchLeaveTicketBalance(context); data.fetchLeaveTicketBalance(context);
// data.fetchMenuEntries(); data.fetchMenuEntries();
} }
@override @override

@ -33,7 +33,7 @@ class TodayAttendanceScreen extends StatefulWidget {
class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> { class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
ValueNotifier<dynamic> result = ValueNotifier(null); ValueNotifier<dynamic> result = ValueNotifier(null);
late DashboardProviderModel data; late DashboardProviderModel data;
bool isNfcEnabled = false, isNfcLocationEnabled = false, isQrEnabled = false, isQrLocationEnabled = false, isWifiEnabled = false, isWifiLocationEnabled = false; bool isNfcEnabled = true, isNfcLocationEnabled = false, isQrEnabled = false, isQrLocationEnabled = false, isWifiEnabled = false, isWifiLocationEnabled = false;
@override @override
void initState() { void initState() {
@ -42,19 +42,19 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
data = Provider.of<DashboardProviderModel>(context, listen: false); data = Provider.of<DashboardProviderModel>(context, listen: false);
} }
checkAttendanceAvailablity() async { void checkAttendanceAvailablity() async {
bool isAvailable = await NfcManager.instance.isAvailable(); bool isAvailable = await NfcManager.instance.isAvailable();
setState(() { setState(() {
AppState().privilegeListModel!.forEach((element) { AppState().privilegeListModel!.forEach((element) {
// Check availability print(element.serviceName.toString() + " " + element.previlege.toString()); // Check availability
if (isAvailable) if (element.serviceName == "enableNFC") {
// if (element.previlege ?? false) if (element.serviceName == "enableNFC") {
isNfcEnabled = true; if (isAvailable) if (element.previlege ?? false) isNfcEnabled = true;
} else if (element.serviceName == "enableQR") { } else if (element.serviceName == "enableQR") {
if (element.previlege ?? false) isQrEnabled = true; if (element.previlege ?? false) isQrEnabled = true;
} else if (element.serviceName == "enableWIFI") { } else if (element.serviceName == "enableWIFI") {
if (element.previlege ?? false) isWifiEnabled = true; if (element.previlege ?? false) isWifiEnabled = true;
} else if (element.serviceName == "enableLocatoinNFC") { } else if (element.serviceName!.trim() == "enableLocationNFC") {
if (element.previlege ?? false) isNfcLocationEnabled = true; if (element.previlege ?? false) isNfcLocationEnabled = true;
} else if (element.serviceName == "enableLocationQR") { } else if (element.serviceName == "enableLocationQR") {
if (element.previlege ?? false) isQrLocationEnabled = true; if (element.previlege ?? false) isQrLocationEnabled = true;
@ -84,7 +84,7 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
actions: [ actions: [
IconButton( IconButton(
onPressed: () { onPressed: () {
data.fetchAttendanceTracking(); data.fetchAttendanceTracking(context);
}, },
icon: Icon( icon: Icon(
Icons.ac_unit, Icons.ac_unit,
@ -190,24 +190,13 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8),
children: <Widget>[ children: <Widget>[
attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () {
showNfcReader(context, onNcfScan: (String? nfcId) async { if (isNfcLocationEnabled) {
print(nfcId); Location.getCurrentLocation((LatLng? latlng) {
Utils.showLoading(context); performNfcAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? "");
try { });
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? ""); } else {
bool status = await model.fetchAttendanceTracking(); performNfcAttendance(model);
Utils.hideLoading(context); }
} catch (ex) {
print(ex);
Utils.hideLoading(context);
Utils.handleException(ex, (msg) {
Utils.confirmDialog(context, msg);
});
}
});
// Location.getCurrentLocation((LatLng? latlng) {
// print(latlng!.longitude.toString());
// });
}), }),
attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () {}), attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () {}),
], ],
@ -244,6 +233,30 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
); );
} }
Future<void> performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async {
if (isNfcLocationEnabled) {
print("nfc location enabled");
} else {
print("nfc not location enabled");
}
showNfcReader(context, onNcfScan: (String? nfcId) async {
print(nfcId);
Utils.showLoading(context);
try {
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng);
bool status = await model.fetchAttendanceTracking(context);
Utils.hideLoading(context);
} catch (ex) {
print(ex);
Utils.hideLoading(context);
Utils.handleException(ex, context, (msg) {
Utils.confirmDialog(context, msg);
});
}
});
}
Widget attendanceMethod(String title, String image, bool isEnabled, VoidCallback onPress) => Container( Widget attendanceMethod(String title, String image, bool isEnabled, VoidCallback onPress) => Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15), borderRadius: BorderRadius.circular(15),

@ -69,23 +69,22 @@ class _LoginScreenState extends State<LoginScreen> {
} }
String? firebaseToken; String? firebaseToken;
GetMobileLoginInfoListModel? loginInfo;
Future<void> checkFirebaseToken() async { Future<void> checkFirebaseToken() async {
try { try {
Utils.showLoading(context); Utils.showLoading(context);
firebaseToken = await _firebaseMessaging.getToken(); firebaseToken = await _firebaseMessaging.getToken();
GetMobileLoginInfoListModel? loginInfo = await LoginApiClient().getMobileLoginInfoNEW(firebaseToken ?? "", Platform.isAndroid ? "android" : "ios"); loginInfo = await LoginApiClient().getMobileLoginInfoNEW(firebaseToken ?? "", Platform.isAndroid ? "android" : "ios");
if (loginInfo == null) { if (loginInfo == null) {
Utils.hideLoading(context); Utils.hideLoading(context);
print("Device token not found");
return; return;
} else { } else {
loginInfo!.deviceToken = firebaseToken;
await checkPrefs(); await checkPrefs();
Utils.hideLoading(context); Utils.hideLoading(context);
performLogin(); performLogin();
} }
} catch (ex) { } catch (ex) {
print(ex);
Utils.hideLoading(context); Utils.hideLoading(context);
Utils.handleException(ex, context, null); Utils.handleException(ex, context, null);
} }
@ -112,7 +111,7 @@ class _LoginScreenState extends State<LoginScreen> {
} }
Utils.hideLoading(context); Utils.hideLoading(context);
if (_autoLogin) { if (_autoLogin) {
Navigator.pushNamed(context, AppRoutes.verifyLastLogin); Navigator.pushNamed(context, AppRoutes.verifyLastLogin, arguments: loginInfo);
} else { } else {
Navigator.pushNamed(context, AppRoutes.verifyLogin, arguments: "$firebaseToken"); Navigator.pushNamed(context, AppRoutes.verifyLogin, arguments: "$firebaseToken");
} }

@ -666,7 +666,7 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
(value) async { (value) async {
Utils.showLoading(context); Utils.showLoading(context);
try { try {
GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(false, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName); GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(true, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName);
GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW( GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW(
AppState().memberLoginList?.pEMAILADDRESS ?? "", AppState().memberLoginList?.pEMAILADDRESS ?? "",
genericResponseModel?.pSESSIONID ?? 0, genericResponseModel?.pSESSIONID ?? 0,
@ -682,6 +682,9 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
AppState().setPrivilegeListModel = genericResponseModel!.privilegeList ?? []; AppState().setPrivilegeListModel = genericResponseModel!.privilegeList ?? [];
AppState().setMemberInformationListModel = genericResponseModel.memberInformationList?.first; AppState().setMemberInformationListModel = genericResponseModel.memberInformationList?.first;
MemberInformationListModel.saveToPrefs(genericResponseModel.memberInformationList ?? []); MemberInformationListModel.saveToPrefs(genericResponseModel.memberInformationList ?? []);
genericResponseModel.privilegeList!.forEach((element) {
print(element.serviceName.toString() + " " + element.previlege.toString()); // Check availability
});
PrivilegeListModel.saveToPrefs(genericResponseModel.privilegeList ?? []); PrivilegeListModel.saveToPrefs(genericResponseModel.privilegeList ?? []);
Utils.saveStringFromPrefs(SharedPrefsConsts.username, AppState().getUserName!); Utils.saveStringFromPrefs(SharedPrefsConsts.username, AppState().getUserName!);
Utils.saveStringFromPrefs(SharedPrefsConsts.password, AppState().password!); Utils.saveStringFromPrefs(SharedPrefsConsts.password, AppState().password!);

@ -165,13 +165,13 @@ class InfoFragment extends StatelessWidget {
ItemDetailView(LocaleKeys.operatingUnit.tr(), itemCreationHeader[index].oPERATINGUNIT?.toString() ?? ""), ItemDetailView(LocaleKeys.operatingUnit.tr(), itemCreationHeader[index].oPERATINGUNIT?.toString() ?? ""),
ItemDetailView(LocaleKeys.category.tr(), itemCreationHeader[index].cATEGORY?.toString() ?? ""), ItemDetailView(LocaleKeys.category.tr(), itemCreationHeader[index].cATEGORY?.toString() ?? ""),
ItemDetailView(LocaleKeys.requester.tr(), itemCreationHeader[index].rEQUESTER?.toString() ?? ""), ItemDetailView(LocaleKeys.requester.tr(), itemCreationHeader[index].rEQUESTER?.toString() ?? ""),
ItemDetailView(LocaleKeys.analyzedBy.tr(), itemCreationHeader[index].aNALYZEDBY.toString() ?? ""), ItemDetailView(LocaleKeys.analyzedBy.tr(), itemCreationHeader[index].aNALYZEDBY?.toString() ?? ""),
ItemDetailView(LocaleKeys.approvedDate.tr(), itemCreationHeader[index].aPPROVEDDATE?.toString() ?? ""), ItemDetailView(LocaleKeys.approvedDate.tr(), itemCreationHeader[index].aPPROVEDDATE?.toString() ?? ""),
ItemDetailView(LocaleKeys.itemType.tr(), itemCreationHeader[index].iTEMTYPE?.toString() ?? ""), ItemDetailView(LocaleKeys.itemType.tr(), itemCreationHeader[index].iTEMTYPE?.toString() ?? ""),
ItemDetailView(LocaleKeys.relatedTo.tr(), itemCreationHeader[index].rELATEDTO?.toString() ?? ""), ItemDetailView(LocaleKeys.relatedTo.tr(), itemCreationHeader[index].rELATEDTO?.toString() ?? ""),
ItemDetailView(LocaleKeys.requestDate.tr(), DateUtil.formatDateToDate(DateUtil.convertStringToDate(itemCreationHeader[index].rEQUESTDATE.toString()), false) ?? ""), ItemDetailView(LocaleKeys.requestDate.tr(), DateUtil.formatDateToDate(DateUtil.convertStringToDate(itemCreationHeader[index].rEQUESTDATE.toString()), false) ?? ""),
ItemDetailView(LocaleKeys.analyzedDate.tr(), itemCreationHeader[index].aNALYZEDDATE?.toString() ?? ""), ItemDetailView(LocaleKeys.analyzedDate.tr(), itemCreationHeader[index].aNALYZEDDATE?.toString() ?? ""),
ItemDetailView(LocaleKeys.urgent.tr(), itemCreationHeader[index].uRGENTFLAGDISP.toString() ?? ""), ItemDetailView(LocaleKeys.urgent.tr(), itemCreationHeader[index].uRGENTFLAGDISP?.toString() ?? ""),
], ],
).objectContainerView(), ).objectContainerView(),
separatorBuilder: (cxt, index) => 18.height, separatorBuilder: (cxt, index) => 18.height,

Loading…
Cancel
Save