Was this article helpful?
Thanks for your feedback
This guide will help you get started with Contentstack Dart SDK to build apps powered by Contentstack.
To use the Contentstack Dart SDK with your existing project, perform the following steps:
To use Contentstack's Dart SDK in your existing project, you need to add the following code within your pubspec.yaml file:
dependencies: contentstack: any
You can download the latest dependency version here.
To initialize the Live Preview feature, you need to set certain configurations:
live_preview = { managementToken: management_token, enable: true, host: 'api.contentstack.io' }
Since the Live Preview Utils SDK is responsible for communication, you need to initialize it within your stack.
Use the following command to initialize the stack:
final stack = Contentstack.stack(api_key, delivery_token, environment, live_preview: live_preview = { managementToken: management_token, enable: true, host: 'api.contentstack.io' });
Note: By default, the host parameter points to the North America endpoint. If your website is hosted on the European data center, then pass the European endpoint against the host parameter.
Use the following code to create an interceptor:
class LoggingInterceptor implements InterceptorContract { @override Future<RequestData> interceptRequest({RequestData data}) async { print(data.toString()); stack.livePreviewQuery(data.toString()) return data; } @override Future<ResponseData> interceptResponse({ResponseData data}) async { print(data.toString()); return data; } }
To install and initialize the Live Preview Utils SDK, you can refer to our SSR Live Preview Setup documentation.
Contentstack SDKs let you interact with the Content Delivery APIs and retrieve content from Contentstack. They are read-only in nature. The SDKs fetch and deliver content from the nearest server via Fastly, our powerful and robust CDN.
To get an entry, you need to specify the content type UID and the UID of the entry.
final entry = stack.contentType('contentTypeUid').entry(entryUid: 'entryUid'); await entry.fetch().then((response) { print(response.toString()); }).catchError((error) { print(error.message.toString()); });
Was this article helpful?
Thanks for your feedback