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:http/http.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 '../main.dart';
@ -81,6 +82,9 @@ class ApiClient {
logger.i("res: " + response.body);
}
var jsonData = jsonDecode(response.body);
if (jsonData["IsAuthenticated"] != null) {
AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
}
if (jsonData["ErrorMessage"] == null) {
return factoryConstructor(jsonData);
} 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));
}
}

@ -79,7 +79,7 @@ class LoginApiClient {
Future<GenericResponseModel?> checkActivationCode(bool isDeviceNFC, String? mobileNumber, String activationCode, String? pUserName) async {
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);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel responseData = GenericResponseModel.fromJson(json);

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

@ -1,5 +1,6 @@
import 'package:flutter/material.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:fluttertoast/fluttertoast.dart';
@ -83,12 +84,12 @@ class Utils {
if (onErrorMessage != null) {
onErrorMessage(errorMessage);
} else {
if (errorMessage.contains("User session is not valid")) {
if (!AppState().isAuthenticated) {
showDialog(
context: cxt,
builder: (cxt) => ConfirmDialog(
message: errorMessage,
onTap: (){
onTap: () {
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.fetchMissingSwipe(context);
data.fetchLeaveTicketBalance(context);
// data.fetchMenuEntries();
data.fetchMenuEntries();
}
@override

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

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

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

@ -165,13 +165,13 @@ class InfoFragment extends StatelessWidget {
ItemDetailView(LocaleKeys.operatingUnit.tr(), itemCreationHeader[index].oPERATINGUNIT?.toString() ?? ""),
ItemDetailView(LocaleKeys.category.tr(), itemCreationHeader[index].cATEGORY?.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.itemType.tr(), itemCreationHeader[index].iTEMTYPE?.toString() ?? ""),
ItemDetailView(LocaleKeys.relatedTo.tr(), itemCreationHeader[index].rELATEDTO?.toString() ?? ""),
ItemDetailView(LocaleKeys.requestDate.tr(), DateUtil.formatDateToDate(DateUtil.convertStringToDate(itemCreationHeader[index].rEQUESTDATE.toString()), false) ?? ""),
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(),
separatorBuilder: (cxt, index) => 18.height,

Loading…
Cancel
Save