Olá, estou tentando consumir minha api para realizar o login, porém está apresentando o seguinte erro:
The method 'then' was called on null.
Receiver: null
Tried calling: then(Closure: (dynamic) => User)
class RestData {
NetworkUtil _netUtil = new NetworkUtil();
static final BASE_URL = "minha url";
static final LOGIN_URL = BASE_URL + "/authentication";
static final token = "token aleatorio";
Future<User> login(String username, String password) {
return _netUtil.post(LOGIN_URL, body: {
"token": token,
"username": username,
"password": password
}).then((dynamic res) { // parametro "then" nesta linha
print(res.toString());
if (res["error"]) throw new Exception(res["error_msg"]);
return new User.map(res["user"]);
});
}
}
import 'dart:async';
class NetworkUtil {
static NetworkUtil _instance = new NetworkUtil.internal();
NetworkUtil.internal();
factory NetworkUtil() => _instance;
Future<dynamic> get() {
return null;
}
post(String loginUrl, {Map<String, String> body}) {}
}
Estou utilizando o auxilio das ferramentas no pubspec.yaml: sqflite e path_provider.
Ressaltando que teste no Postman a API funciona perfeitamente.
Se alguém tiver alguma dica, ficarei grata!!
_netUtil.post
... pois o erro está aí. – Julio Henrique Bitencourt 6/10/20 às 21:36