I have this JSON from my API in localhost
{"username":"coreadmin","password":"adminAdmin","name_display":"gm","role_id":1,"position":"admin","firstname":"gm","lastname":"gm","phone":"1233-123-1233","email":"test@admin.test","country":"none","dt_created":"2021-09-27T02:17:09.000Z","dt_updated":"2021-09-27T02:17:09.000Z"}
That data is displayed when I access it via web browser.
I attempted to get the data and display it via flutter, here's my code :
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../models/users.dart' as users_model;
class FetchJson {
static Future<users_model.Users> fetchCredential(String username, String password) async {
final response = await http.get(Uri.parse('http://localhost:7777/login?username=coreadmin&password=adminADMIN'));
if (response.statusCode == 200) {
return users_model.Users.fromJson(jsonDecode(response.body));
} else {
throw Exception('Failed to load users credentials: ' + response.statusCode.toString());
}
}
}
But there's no response.body
while response.statusCode == 200
The error is
Error: FormatException: SyntaxError: Unexpected end of JSON input