setData method
Writes to the object referred to by this AlgoliaObjectReference.
If the object does not yet exist, it will be created.
Implementation
Future<AlgoliaTask> setData(Map<String, dynamic> data) async {
try {
assert(_index != null && _index != '*' && _index != '',
'IndexName is required, but it has `*` multiple flag or `null`.');
String url = '${algolia._host}indexes/$_index';
if (_objectId != null) {
url = '$url/$_objectId';
}
Response response = await post(
Uri.parse(url),
headers: algolia._header,
body: utf8.encode(json.encode(data, toEncodable: jsonEncodeHelper)),
encoding: Encoding.getByName('utf-8'),
);
Map<String, dynamic> body = json.decode(response.body);
return AlgoliaTask._(algolia, _index, body);
} catch (err) {
Map<String, dynamic> body = json.decode(err.toString());
return AlgoliaTask._(algolia, _index, body);
}
}