Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Parsing double to String is not accepted in function

I need to convert a double variable to string to upload it as part of a http post request to the server:

  final response = await http.post(Uri.parse(url), body: {
      "fecha_inicio": _fechaInicioBBDD,
      "fecha_fin": _fechaFinalBBDD,
      "latitud": _controllerLatitud.text,
      "longitud": _controllerLongitud.text,
      "calle": _controllerDireccion.text,
      "descripcion": _controllerDescripcion.text,
      "tipo_aviso": tipoAviso,
      "activar_x_antes": double.parse(_horas.toString())

    });

The parameter "activar_x_antes": double.parse(_horas.toString()) is throwing an exception when executing the app:

Unhandled Exception: type 'double' is not a subtype of type 'String' in type cast

The value for _horas = 4.0

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use

 final response = await http.post(Uri.parse(url), body: {
      "fecha_inicio": _fechaInicioBBDD,
      "fecha_fin": _fechaFinalBBDD,
      "latitud": _controllerLatitud.text,
      "longitud": _controllerLongitud.text,
      "calle": _controllerDireccion.text,
      "descripcion": _controllerDescripcion.text,
      "tipo_aviso": tipoAviso,
      "activar_x_antes": _horas.toString()

    });

_horas.toString()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading