You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.6 KiB
Dart
97 lines
2.6 KiB
Dart
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
// SharedPreferences sharedPref = new SharedPreferences();
|
|
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED }
|
|
AppSharedPreferences sharedPref = new AppSharedPreferences();
|
|
|
|
const String INSERT_DEVICE_IMEI =
|
|
'Services/Patients.svc/REST/Patient_INSERTDeviceIMEI';
|
|
const String SELECT_DEVICE_IMEI =
|
|
'Services/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI';
|
|
|
|
class AuthProvider with ChangeNotifier {
|
|
bool isLogin = false;
|
|
bool isLoading = true;
|
|
AuthProvider() {
|
|
getUserAuthentication();
|
|
}
|
|
|
|
void getUserAuthentication() async {
|
|
Map profile = await sharedPref.getObject(USER_PROFILE);
|
|
if (profile != null) {
|
|
isLoading = false;
|
|
isLogin = true;
|
|
} else {
|
|
isLoading = false;
|
|
isLogin = false;
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
APP_STATUS get stutas {
|
|
if (isLoading) {
|
|
return APP_STATUS.LOADING;
|
|
} else {
|
|
if (this.isLogin) {
|
|
return APP_STATUS.AUTHENTICATED;
|
|
} else {
|
|
return APP_STATUS.UNAUTHENTICATED;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Future<dynamic> login(UserModel userInfo) async {
|
|
// try {
|
|
// dynamic localRes;
|
|
|
|
// await BaseAppClient.post(LOGIN_URL,
|
|
// onSuccess: (dynamic response, int statusCode) {
|
|
// localRes = response;
|
|
// }, onFailure: (String error, int statusCode) {
|
|
// throw error;
|
|
// }, body: userInfo.toJson());
|
|
|
|
// return Future.value(localRes);
|
|
// } catch (error) {
|
|
// print(error);
|
|
// throw error;
|
|
// }
|
|
// }
|
|
|
|
Future<dynamic> insertDeviceImei(imei) async {
|
|
try {
|
|
dynamic localRes;
|
|
|
|
await new BaseAppClient().post(INSERT_DEVICE_IMEI,
|
|
onSuccess: (dynamic response, int statusCode) {
|
|
localRes = response;
|
|
}, onFailure: (String error, int statusCode) {
|
|
throw error;
|
|
}, body: imei);
|
|
return Future.value(localRes);
|
|
} catch (error) {
|
|
print(error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
Future<dynamic> selectDeviceImei(imei) async {
|
|
try {
|
|
dynamic localRes;
|
|
await new BaseAppClient().post(SELECT_DEVICE_IMEI,
|
|
onSuccess: (dynamic response, int statusCode) {
|
|
localRes = response;
|
|
}, onFailure: (String error, int statusCode) {
|
|
throw error;
|
|
}, body: imei);
|
|
return Future.value(localRes);
|
|
} catch (error) {
|
|
print(error);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|