0
The following situation is occurring in my project. I have a model that has a property like Datetime, in Tojson I pass the date to the json using toIso8601String, in case I just put the current date when pressing the button
onPressed: () {
controllerPV.pedidoVenda.dATA = new DateTime.now();
controllerPV.pedidoVenda.cANCELADO = 'N';
controllerPV.pedidoVenda.mSGADICIONAL = controllerMsgEdicional.text;
controller.submit();
}
And then at the repositories I ride the body and give a post
Parametros parametros = Parametros();
await parametros.buscarParametros();
var body = json.encode(
pvenda.toJson(),
);
http.Response response = await http.post(
parametros.url_api + URL_PVendasInserir,
headers: {
"Content-type": "application/json; charset=UTF-8"
},
body: body
);
the date converted, stays this way
But when giving the post returns the status 500 and the message "Cannot read JSON Property of type = "Tdatetime", invalid value.". So I took the body and I ran a test on Postman, and I realized that changing the date 2021-03-06T10:42:38.774478 to 2021-03-06T10:42:38 worked, so I assume that the error relates to that part of the millisecond (.774478). Would I have some way to get them out when it’s time to convert, or should I do something else ?
If the error is STATUS 500 after the post, probably the problem is in your API... You need to tidy up inside your API so it understands the TIMESTAMP type or cast to turn into date before posting
– Matheus Ribeiro
I understood, and how I could convert Datetime to Timestamp ?
– Iury Pereira