title: FormatException: Unexpected end of input (at character 2) ^ in flutter
body: <p>I have a form with 6 fields. I am trying to send data to server after the button is pressed. But after pressing the button I got error: <strong>FormatException: Unexpected end of input (at character 2) ^</strong>. There are some number fields and some normal text fields. Do not understand why this error is occurring. Please help. Thanks in advance. Here is my dart code:</p>
  <pre><code>Future&lt;SubmitData&gt; userData(
    String uid,
    String saleAmount,
    String quantity,
    String rate,
    String brokerName,
    String partyName,
    String amountReceivable) async {
     Map&lt;String, dynamic&gt; map = {
     'uid': uid,
     'saleAmount': saleAmount,
     'quantity': quantity,
     'rate': rate,
     'brokerName': brokerName,
     'partyName': partyName,
     'amountReceivable': amountReceivable
   };
  
   final http.Response response = await http.post(
    'my php page',
     headers: &lt;String, String&gt;{
     'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(map),
   );
  
   if (response.statusCode == 201 || response.statusCode == 200) {
    return SubmitData.fromJson(json.decode(response.body));
   } else {
    throw Exception('Failed to submit.');
   }
  }
  
     class SubmitData {
      final String type;
  
      SubmitData({this.type});
  
      factory SubmitData.fromJson(Map&lt;String, dynamic&gt; json) {
      return SubmitData(type: json['type']);
    }
    }
  
    class UserForm extends StatefulWidget {
     @override
     State&lt;StatefulWidget&gt; createState() {
     return _UserForm();
    } 
   }
  
  class _UserForm extends State&lt;UserForm&gt; {
   final _formKey = GlobalKey&lt;FormState&gt;();
   final uid = TextEditingController();
   final myController = TextEditingController();
   final myController2 = TextEditingController();
   final myController3 = TextEditingController();
   final myController4 = TextEditingController();
   final myController5 = TextEditingController();
   final myController6 = TextEditingController();
  
   @override
   void dispose() {
     // Clean up the controller when the widget is disposed.
     uid.dispose();
     myController.dispose();
     myController2.dispose();
     myController3.dispose();
     myController4.dispose();
     myController5.dispose();
     myController6.dispose();
     super.dispose();
   }
  
   Future&lt;SubmitData&gt; _futureSubmitData;
   @override
   Widget build(BuildContext context) {
     return Form(
      key: _formKey,
      child: (_futureSubmitData == null)
        ? Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: &lt;Widget&gt;[
              Visibility(
                visible: false,
                child: TextFormField(
                  controller: uid,
                  initialValue: '1',
                ),
              ),
              TextFormField(
                controller: myController,
                keyboardType: TextInputType.numberWithOptions(decimal: true),
                decoration:
                    InputDecoration(hintText: 'Sale amount as per party'),
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Please enter amount.';
                  }
                  return null;
                },
              ),
              TextFormField(
                controller: myController2,
                keyboardType: TextInputType.number,
                decoration: InputDecoration(hintText: 'Item quantity'),
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Please enter quantity.';
                  }
                  return null;
                },
              ),
              TextFormField(
                controller: myController3,
                keyboardType: TextInputType.numberWithOptions(decimal: true),
                decoration: InputDecoration(hintText: 'Rate'),
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Please enter rate.';
                  }
                  return null;
                },
              ),
              TextFormField(
                controller: myController4,
                decoration: InputDecoration(hintText: 'Broker name'),
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Please enter broker name.';
                  }
                  return null;
                },
              ),
              TextFormField(
                controller: myController5,
                decoration: InputDecoration(hintText: 'Party name'),
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Please enter party name.';
                  }
                  return null;
                },
              ),
              TextFormField(
                controller: myController6,
                keyboardType: TextInputType.numberWithOptions(decimal: true),
                decoration: InputDecoration(
                    hintText: 'Amount receivable as per party'),
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Please enter amount.';
                  }
                  return null;
                },
              ),
              Container(
                margin: EdgeInsets.all(10.0),
                child: RaisedButton(
                  color: Colors.purple[400],
                  textColor: Colors.white,
                  onPressed: () {
                    if (_formKey.currentState.validate()) {
                      setState(() {
                        _futureSubmitData = userData(
                            uid.text,
                            myController.text,
                            myController2.text,
                            myController3.text,
                            myController4.text,
                            myController5.text,
                            myController6.text);
                      });
                    }
                  },
                  child: Text('Submit', style: TextStyle(fontSize: 18.0)),
                ),
              ),
            ],
          )
        : FutureBuilder&lt;SubmitData&gt;(
            future: _futureSubmitData,
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                if (snapshot.data.type == '1') {
                  showDialog(
                    context: context,
                    builder: (context) {
                      return AlertDialog(
                        content: Text('Data submitted successfully.'),
                      );
                    },
                  );
                  return Text('.');
                } else {
                  showDialog(
                    context: context,
                    builder: (context) {
                      return AlertDialog(
                        content: Text(
                            'Data not submitted. You have already submitted for today.'),
                      );
                    },
                  );
                  return Text('.');
                }
              } else if (snapshot.hasError) {
                return Text(&quot;${snapshot.error}&quot;);
              }
              return Center(child: CircularProgressIndicator());
            },
          ),
       );
      }
    }
  </code></pre>