'Cannot send to database after update
I'm a new flutter user, so this time I'm having problems when I want to update the data can't be sent (save) to the database. because there is no error but the data is not saved. Please help me
This is my problem https://www.youtube.com/watch?v=38ZoHWsJ47k
Function update
void _update() async {
setState(() {
_isLoading = true;
});
Map<String, String> data = {
"body1" : _nama_debiturController.text,
"body2": _alamatController.text,
"body3": _no_telpController.text,
"body4" : _no_ktpController.text,
"body5" : _no_selularController.text
};
print(data);
var res = await Network().updateData(data, 'mstdebitur');
var body = json.decode(res.body);
if (res.statusCode == 200) {
SharedPreferences localStorage = await SharedPreferences.getInstance();
localStorage.setString('mstdebitur', json.encode(body['mstdebitur']));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Berhasil Disimpan'),
duration: Duration(seconds: 2),
));
} else {
if (body['message']['nama_debitur'] != null) {
_showMsg(body['message']['nama_debitur'][0].toString());
} else if (body['message']['alamat'] != null) {
_showMsg(body['message']['alamat'][0].toString());
} else if (body['message']['no_telp'] != null) {
_showMsg(body['message']['no_telp'][0].toString());
}
else if (body['message']['no_ktp'] != null) {
_showMsg(body['message']['no_ktp'][0].toString());
}
else if (body['message']['no_selular'] != null) {
_showMsg(body['message']['no_selular'][0].toString());
}
ScaffoldMessenger.of(context)
.showSnackBar(new SnackBar(content: Text("Gagal")));
}
setState(() {
_isLoading = false;
});
}
}
api.dart
updateData(apiURL, id, body) async {
var fullUrl = _url + apiURL + '/' + id.toString();
await _getToken();
return await http.put(
fullUrl,
headers: _setHeaders(),
body: json.encode(body),
);
}
nasabah_service.dart
static Future<List<Nasabah>> updateUser(id) async {
Map<String, String> data;
final response = await Network().updateData(baseUrl, id, data);
List<Nasabah> list = parseResponse(response.body);
return list;
}
can you help me ? Because
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
