flutter: FormatException: Unexpected end of input (at character 1)

435 Views Asked by At

I am facing this issue when I try to log into my app. I get this error message "flutter: FormatException: Unexpected end of input (at character 1)".

This is the const API_auth = "https://www.assofacile.it/login/wp_login.php";

Does anybody knows how to solve this issue?

Future save(BuildContext context) async {
    var localUrl  = LOCAL_auth;
    var puclicUrl = API_auth;

    try {
      var response = await http.post(Uri.parse(puclicUrl),
          //headers: <String, String>{'Context-Type': 'application/json;charSet=UTF-8'},
          body: <String, String>{
            "username": username.text,
            "password": password.text,
          });
      // if(response.body.isNotEmpty) {
      //   json.decode(response.body);
      // }
      if (response.statusCode == 200) {
          var data = jsonDecode(response.body.toString());
          if(response.body.isNotEmpty) {
            json.decode(response.body);
            Navigator.push(
              context, MaterialPageRoute(
              builder: (context) => const HomePage(),
            ),
            );
          }
           // Navigator.push(
           //   context, MaterialPageRoute(
           //     builder: (context) => const HomePage(),
           //   ),
           // );
           print("Logged in");
      } else {
          print('failed');
      }
    } catch (e) {
        print(e.toString());
    }
  }
0

There are 0 best solutions below