save method
Implementation
Future<bool> save({String? parentguid, int flag = 0}) async {
bool r = false;
if (_code != '') {
//await httpSvc.loadAccount(code: _code);
if (Oph.curPreset.hostguid != null &&
Oph.curPreset.hostguid != '' &&
Oph.curPreset.isLogin!) {
String url = Oph.curPreset.serverURL! +
Oph.curPreset.rootAccountId! +
'/' +
Oph.curPreset.apiURL! +
'?suba=' +
Oph.curPreset.accountId! +
'&mode=save&code=' +
_code!;
var client = new http.Client();
var request = new http.MultipartRequest('POST', Uri.parse(url));
print(url);
Map<String, String> body = {
'hostguid': Oph.curPreset.hostguid!,
'cfunctionlist': _frm!.guid,
'cid': parentguid ?? _frm!.guid,
'mode': 'save',
'unique': DateFormat('yyyyMMddHHmmss').format(DateTime.now())
};
if (_frm != null) {
for (FrmField f in _frm!.fields!) {
if ((f.value != null) && f.boxType != 'profileBox') {
body[f.fieldName] =
f.boxType == 'autosuggestBox' ? f.value! : f.controller!.text;
} else {
File? imageFile = f.imageFile!;
body[f.fieldName] = basename(imageFile.path);
var stream = new http.ByteStream(imageFile.openRead());
stream.cast();
imageFile.length().then((length) {
var multipartFile = new http.MultipartFile(
'file', stream, length,
filename: basename(imageFile.path));
//contentType: new MediaType('image', 'png'));
request.files.add(multipartFile);
});
}
}
request.fields.addAll(body);
//request.bodyFields = body;
try {
var response = await client
.send(request)
.timeout(const Duration(seconds: timeout));
var value = await response.stream.bytesToString();
if (value != '') {
XmlDocument xmlDoc = XmlDocument.parse(value);
List<String> l1 = xmlDoc
.findAllElements("guid")
.map((node) => node.text)
.toList();
List<String> l2 = xmlDoc
.findAllElements("message")
.map((node) => node.text)
.toList();
// List<String> l3 = xmlDoc
// .findAllElements("unique")
// .map((node) => node.text)
// .toList();
if (l1.length > 0 && l1[0].length > 0) {
//_guid=l1[0];
_frm!.guid = l1[0];
r = true;
// if (l3.length > 0 && l3[0].length > 0) {
// unique = l3[0];
// //_frm=getForm(code:code,guid:guid);
// }
}
if (l2[0] != '') {
_msg = l2[0];
print(_msg);
} else {
_msg = '';
r = true;
}
}
} on SocketException catch (e) {
_msg = "Socket Error: " + e.message;
_errorback!();
} catch (e) {
//_msg = e.message;
//_errorback();
}
}
//} else {
//_msg = "Unauthorized";
//print(_msg);
}
}
return r;
}