executeFuture method
Future<String?>
executeFuture(
- String _method,
- Parameter _parameter,
- OnSuccessListener _onSuccessListener
Implementation
Future<String?> executeFuture(String _method,
Parameter _parameter, OnSuccessListener _onSuccessListener) async {
// String token = await Preferences.getToken();
// if (token == null) {
// token =
// 'e233df41ffb1bf15236d40f2a524bd5596913449924c8476903182c49a83c7c5';
// }
var requestParams = "";
var index = 0;
Parameter paramnew = Parameter();
await Helper().checksodium().then((sodium) async {
ParameterRegisterNew par = await Helper().encryparamater(sodium, _parameter.getJson(),"apikey");
paramnew.set("nvidia", par.postData);
paramnew.set("samsung", par.bla1);
paramnew.set("fullhd", par.bla2);
});
var nationcode = _parameter.data?["nation_code"].toString();
// print("nation_code ${nationcode}");
var request = http.MultipartRequest(
"POST", Uri.parse(_getUrl(_method)+"?nation_code=${nationcode}"));
if (Config.openApi) {
// print("request param method${_method} ${requestParams} ");
// print("request ${_getUrl(_method)}?${requestParams}");
// print("request2 ${request.url.toString()}");
}
print("request game ${_getUrl(_method)}?${requestParams}");
print("request2 game ${request.url.toString()}");
paramnew.data?.forEach((key, value) {
if (value != null) {
request.fields[key] = '$value';
// print("v $v");
}
});
try {
var response = await request.send();
// timeout(timeoutDuration, onTimeout: () {
// _handleResponseError(
// null, null, _method, _parameter, _onSuccessListener);
// return;
// });
String body = await response.stream.bytesToString();
// print("respon ${body}");
if (response != null) {
if (response.statusCode == 200) {
if (body != null) {
return body;
}
}
// else if (response.statusCode == 404){
// Helper().goErrorModalButton(context,
// message: "Service is temporarily unavailable now, please try again later", oketitle: "Close", onOke: () {
// Navigator.of(context).pushReplacement(
// new MaterialPageRoute(
// builder: (context) => SplashSellonScreen()),
// );
// });
// }
else {
this._onErrorListener!(
new Error(this, response.statusCode, "${body}"));
_handleResponseError(response.statusCode.toString(), body, _method,
_parameter, _onSuccessListener);
}
} else {
if(response != null && response.statusCode != null){
this._onErrorListener!(
new Error(this, response.statusCode, "${body}"));
_handleResponseError(response.statusCode.toString(), body, _method,
_parameter, _onSuccessListener);
}else{
if (!Config.isMaintanceShutDown){
// SellonRouter.makeFirst(_context, MaintanceScreen(isErrorApi: true,));
}
}
}
} catch (exp) {
if (_onExceptionListener != null && exp is Exception) {
_onExceptionListener!(exp);
}
}
}