Line data Source code
1 : import 'dart:async'; 2 : import 'package:contentstack/client.dart'; 3 : import 'package:contentstack/contentstack.dart'; 4 : import 'package:contentstack/src/entry_queryable.dart'; 5 : 6 : /// 7 : /// An entry is the actual piece of content created 8 : /// using one of the defined content types. 9 : /// Read more about Entries. 10 : /// https://www.contentstack.com/docs/content-managers/work-with-entries/ 11 : /// 12 : /// All Entries: 13 : /// The Get all entries call fetches the list of all the entries of a 14 : /// particular content type 15 : /// 16 : /// Single Entry: 17 : /// The Get a single entry request fetches a particular entry of a content type 18 : /// 19 : class Entry extends EntryQueryable { 20 1 : Entry([this._uid, this._client, this._contentTypeUid]) { 21 5 : parameter['environment'] = _client.stackHeaders['environment']; 22 3 : if (_contentTypeUid != null && _contentTypeUid.isNotEmpty) { 23 1 : _path = 24 5 : '/${_client.stack.apiVersion}/content_types/$_contentTypeUid/entries'; 25 : } 26 : } 27 : 28 : final HttpClient _client; 29 : final String _contentTypeUid; 30 : String _path; 31 : final String _uid; 32 : 33 : /// Applies query on entries 34 1 : Query query() { 35 3 : return Query(_client, _contentTypeUid); 36 : } 37 : 38 : /// The Get a single entry request fetches a particular entry of a content type. 39 : /// 40 : /// Example: 41 : /// 42 : /// import 'package:contentstack/contentstack.dart' as contentstack; 43 : /// 44 : /// final contentstack.Stack stack = contentstack.Stack(apiKey, deliveryToken, environment); 45 : /// entry = stack.contentType('faq').entry(entryUid: Credential.entryUid); 46 : /// entry.includeReference('categories'); 47 : /// await entry.fetch().then((response) { 48 : /// if(response is Error){ 49 : /// print(response.errorMessage); 50 : /// }else{ 51 : /// print(response.toString()); 52 : /// } 53 : /// }).catchError((onError) { 54 : /// expect('invalid url requested', onError.message); 55 : /// }); 56 : /// 57 1 : Future<T> fetch<T, K>() async { 58 1 : if (_uid == null) { 59 0 : throw Exception('Provide entry uid to fetch single entry'); 60 : } 61 8 : final uri = Uri.https(_client.stack.endpoint, '$_path/$_uid', parameter); 62 2 : return _client.sendRequest<T, K>(uri); 63 : } 64 : }