How can I make post requests from flutter.I need to authenticate a user with his email address and password. Please help
tried with the following code
I use
import 'dart:async' show Future;
import 'dart:io'
show HttpClient, HttpClientBasicCredentials, HttpClientCredentials;
import 'package:http/http.dart' show BaseClient, IOClient;
typedef Future HttpAuthenticationCallback(
Uri uri, String scheme, String realm);
HttpAuthenticationCallback _basicAuthenticationCallback(
HttpClient client, HttpClientCredentials credentials) =>
(Uri uri, String scheme, String realm) {
client.addCredentials(uri, realm, credentials);
return new Future.value(true);
};
BaseClient createBasicAuthenticationIoHttpClient(
String userName, String password) {
final credentials = new HttpClientBasicCredentials(userName, password);
final client = new HttpClient();
client.authenticate = _basicAuthenticationCallback(client, credentials);
return new IOClient(client);
}
final http =
createBasicAuthenticationIoHttpClient(_config.userName, _config.password);
http.get(...)