I am trying to create a simple wrapper for the rest client by facing following issue:
I have an external class:
typedef void Callback(int code, String body);
class HttpClient {
void post(String url, Map<String, String> headers, Map<String, String> params,
Callback callback) async {
final encoding = Encoding.getByName('utf-8');
Response response =
await post(url, headers: headers, body: params, encoding: encoding);
callback(200, "lol");
}
}
My await post(...) is highlighted and says the following error: "The expression here has a type of 'void', and therefore can't be used.
Interesting, that if I change my method to private the highlighting disappears.
I can also declare post as a private function and then call it from another public fuction passing all the same params and it works.
How should I write this function and then call it another place? Thanks!
EDIT
Thanks for @Jack I could find the solution:
import should be
import 'package:http/http.dart' as http;
And Response response = await post(url, headers: headers, body: params, encoding: encoding);
Should be changed to
var response =
await http.post(url, headers: headers, body: params, encoding: encoding);