callapilogin method
dynamic
callapilogin()
Implementation
callapilogin() {
isLoading = true;
setState(() {});
ApiSellon.createDefaultParams((parameter) {
Preferences.getFirebase().then((fcm) {
Helper().getId2().then((idvl) {
if (idvl != null && idvl != '') {
parameter.set("device_id", idvl);
}
String method = "";
parameter.set("is_emulator", Config.emulator! ? "1" : "0");
if (widget.registerWith == RegisterWith.emailSign) {
parameter.set('username', emailController.text);
parameter.set('password', passwordController.text);
// parameter.set('password', "As1");
method = MethodsSellon.pelangganLogin;
} else if (widget.registerWith == RegisterWith.phoneSign) {
parameter.set('telp', phoneNumberController.text);
// parameter.set('password', passwordController.text);
method = MethodsSellon.pelangganLoginPhoneNumber;
} else {
String idmed = widget.registerWith == RegisterWith.googleSign
? "google_id"
: widget.registerWith == RegisterWith.facebookSign
? "fb_id"
: "apple_id";
parameter.set(idmed, widget.id!);
parameter.set('email', emailController.text);
method = Config.AppVersion == VersionApps.indonesia
? MethodsSellon.pelangganLoginSosmed3
: MethodsSellon.pelangganLoginSosmed;
}
parameter.set('fcm_token', fcm!);
parameter.set('device', Platform.isIOS ? 'ios' : 'android');
parameter.set("game_id", Config.idGame);
Helper().checksodium().then((sodim) async{
ParameterRegisterNew par = await Helper().encryparamater(sodim, parameter.getJson(),widget.registerWith == RegisterWith.emailSign || widget.registerWith == RegisterWith.phoneSign ? "register": "sosmed");
Parameter paranew = Parameter();
paranew.set("bla2", par.bla1);
paranew.set("bla3", par.bla2);
paranew.set("bla1", par.postData);
ApiSellon api = ApiSellon(context);
api.setErrorListener((error) {
Ui(context).errorAlert(message: error.errMessage);
// Toast.show(error.errMessage, context);
if (Config.verificationPhone != null) {
Config.verificationPhone = false;
SellonRouter.pop(context);
}
isLoading = false;
setState(() {});
});
//cok masalah register
api.execute(method, SellonMethod.post,
// Config.AppVersion == VersionApps.indonesia ? method == MethodsSellon.pelangganLoginPhoneNumber || method == MethodsSellon.pelangganLogin ?
paranew , (response) {
Map data = response.data()['data'];
String apises = response.data()['data']['apisess'];
var it = utf8.encode(apises);
var sha256capises = sha256.convert(it);
Preferences.setApises(sha256capises.toString());
// Preferences.setProfile(jsonEncode(data['pelanggan']));
// Preferences.setNeighborhood(Config.neighborhood!);
// Preferences.setid(data["pelanggan"]["id"]);
if (widget.registerWith != RegisterWith.emailSign &&
widget.registerWith != RegisterWith.phoneSign) {
Preferences.setidMed(widget.id!);
}
Preferences.setemail(emailController.text);
if (widget.registerWith == RegisterWith.emailSign) {
Preferences.setPassword(passwordController.text);
} else {
Preferences.setPassword("");
}
// if (widget.registerWith == RegisterWith.googleSign) {
// Preferences.setSignWith("google");
// }
//
// if (widget.registerWith == RegisterWith.appleSign) {
// Preferences.setSignWith("apple");
// }
//
// if (widget.registerWith == RegisterWith.facebookSign) {
// Preferences.setSignWith("fb");
// }
//
// if (widget.registerWith == RegisterWith.emailSign) {
// Preferences.setSignWith("email");
// }
//
// if (widget.registerWith == RegisterWith.phoneSign) {
// Preferences.setSignWith("phone");
// }
if (response.data()['status'] == 200) {
if (Config.AppVersion == VersionApps.singapura) {
if (response.data()['data']['pelanggan']['telp_is_verif'] ==
"0" ||
response.data()['data']['pelanggan']['telp_is_verif'] ==
0) {
SellonRouter.push(
context,
VerificationPhoneScreen(
phone: phoneNumberController.text,
email: emailController.text,
registerWith: widget.registerWith,
password: passwordController.text,
// isPhoneNumberHere: _mobileNumber == phoneNumberController.text,
id: widget.id,
data: data,
regis: this,
));
} else {
saveLogin(data);
// go to home
// SellonRouter.makeFirst(context, HomeScreen());
}
} else {
saveLogin(data);
// go to home
// SellonRouter.makeFirst(context, HomeScreen());
}
} else {
saveLogin(data);
// go to home
// SellonRouter.makeFirst(context, HomeScreen());
// if (widget.registerWith == RegisterWith.phoneSign && response.data()!['data']['pelanggan']['telp_is_verif'] ==
// "0" ||
// response.data()!['data']['pelanggan']['telp_is_verif'] == 0) {
// SellonRouter.push(
// context,
// VerificationPhoneScreen(
// phone: phoneNumberController.text,
// email: emailController.text,
// registerWith: widget.registerWith,
// password: passwordController.text,
// id: widget.id,
// isLoginAgain: false,
// isID: true,
// ));
// }
// else{
// SellonRouter.makeFirst(context, HomeScreen());
// }
}
});
// else {}
});
});
});
});
}