Send integer value from text field in Flutter to Go backend

Arjun Malhotra

I am trying to send data of a Student to be added in SQL database by using Go. This is the code :

 final jsonbody = jsonEncode(<String, dynamic>{
                    "StudentId": idController.text,
                    "StudentName": snController.text,
                    "FatherName": fnController.text,
                    "MotherName": mnController.text,
                    "Cgpa": cgController.text,
                    "City": ctController.text
                  });
                  print(jsonbody);
                  final responseofAPI = await http.post(
                      Uri.parse(url),
                      headers: {'Content-Type': 'application/json'},
                      body: jsonbody);
                  print("Code -----> ${responseofAPI.statusCode}");

                  print(jsonDecode(responseofAPI.body));
                  print(responseofAPI.body);

And this is the response I am getting :

I/flutter (22041): {"StudentId":"84","StudentName":"Mukul","FatherName":"Mukesh","MotherName":"Swati","Cgpa":"7","City":"Kanpur"}
I/flutter (22041): Code -----> 400
E/flutter (22041): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: FormatException: Unexpected end of input (at character 1)
E/flutter (22041): 
E/flutter (22041): ^

I have to send the studentId and Cgpa as integer values thats the reason I think the error is coming from.It is now going as string. How can I send integer value from Frontend?

rasityilmaz

If you commit that the string value from the controller is integer, you can convert the value to integer with int.parse("")

final jsonbody = jsonEncode(<String, dynamic>{
                        "StudentId": int.parse(idController.text),
                        "StudentName": snController.text,
                        "FatherName": fnController.text,
                        "MotherName": mnController.text,
                        "Cgpa": int.parse(cgController.text),
                        "City": ctController.text
                      });
                      print(jsonbody);
                      final responseofAPI = await http.post(
                          Uri.parse('http://192.168.1.19:8081/everyStudent'),
                          headers: {'Content-Type': 'application/json'},
                          body: jsonbody);
                      print("Code -----> ${responseofAPI.statusCode}");
    
                      print(jsonDecode(responseofAPI.body));
                      print(responseofAPI.body);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Flutter: is there any possibility to send the button value to the text field?

How to automatically set value for a text field based on value from another text field in Flutter?

Default value for Text Field flutter?

Flutter Make Text Field go Up with keyboard

Send text field value using href to php

How to send a text with button(without text field)? (Flutter)

Is there a way to display the barcode value in a text field in Flutter?

substract integer value from datetime field

Retrieving value from text field

How to save text field input as integer - Flutter and Firestore

Send text from HTML search bar to backend through JS

Go from TEXT field to foreign key

how to send value to javascript from input field

Send text to Text Field

send value from Angular service App to C# backend controller

Text field value. Display one value send another to the server

checking input field value from backend array that present or not in array

Issue with saving value from Select2 field in WooCommerce backend

get Field value from Firestore with flutter

Check if the integer value of a text field is valid in a switch statement [swift]

I want to calculate the value of an integer in a text field while ignoring a string of text that is required before the integer?

Unable to send websocket data from flutter app to go server

How to send react native text field value as JSON.stringify

Convert numbers from a text field (in a GUI) into an integer in Python-3

Obtain value from KivyMD text field?

How to get numeric value from text field?

Get value from text field and store it as array

Getting value using pywinauto from text field

Pass a Value from Button to Text Field in JavaScript