fetch<T, K> method
The Get a single entry
request fetches a particular
entry of a content type.
Example:
import 'package:contentstack/contentstack.dart' as contentstack;
final contentstack.Stack stack =
contentstack.Stack('apiKey', 'deliveryToken', 'environment');
entry = stack.contentType('contentType').entry(entryUid: 'entryUid');
entry.includeReference('categories');
await entry.fetch().then((response) {
if(response is Error){
print(response.errorMessage);
}else{
print(response.toString());
}
}).catchError((onError) {
expect('invalid url requested', onError.message);
});
Implementation
Future<T> fetch<T, K>() async {
if (_uid == null) {
throw Exception('Provide entry uid to fetch single entry');
}
final preview = _client.stack.livePreview;
if (preview != null && preview.isNotEmpty) {
validateLivePreview(preview, _client, _contentTypeUid);
}
final uri = Uri.https(_client.stack.endpoint, '$_path/$_uid');
final request =
Uri.parse(uri.toString()).resolveUri(Uri(queryParameters: parameter));
return _client.sendRequest<T, K>(request);
}