Stack constructor
Create a new Stack instance with stack's apikey, token, environment name and Optional parameters like. Throws an ArgumentError if apiKey, deliveryToken and environment is not passed. Optional Parameters: apiVersion: (Optional) apiVersion for the api region: (Optional) region is type of Region i.e US and EU host: (Optional) host is the host for the api client: (Optional) if developer wants to set their own client instance livePreview: (Optional) enables livePreview for entry/query provide livePreview object like below.
final Map<String, dynamic> livePreview = {
'authorization': management_token,
'enable': true,
'host': 'live.contentstack.com',
'include_edit_tags': true,
'edit_tags_type': editTags,
};
import 'package:contentstack/contentstack.dart' as contentstack; var stack = contentstack.Stack('api_key', 'delivery_token', environment)
Example:
final stack = contentstack.Stack(apiKey, deliveryToken, environment);
Implementation
Stack(
this._apiKey,
this._deliveryToken,
this._environment, {
this.apiVersion = 'v3',
this.region = Region.us,
this.branch,
String host = 'cdn.contentstack.io',
BaseClient client,
this.livePreview,
}) : _host = (region == Region.us)
? host
: (host == 'cdn.contentstack.io'
? 'eu-cdn.contentstack.com'
: 'eu-$host') {
if (region == Region.azure_na) {
_host = 'azure-na-$host';
if (host == 'cdn.contentstack.io') {
_host = 'azure-na.contentstack.com';
}
}
if (_apiKey.replaceAll(RegExp('\\W'), '').isEmpty ?? true) {
throw ArgumentError.notNull('apiKey');
}
if (_deliveryToken.replaceAll(RegExp('\\W'), '').isEmpty ?? true) {
throw ArgumentError.notNull('deliveryToken');
}
if (_environment.replaceAll(RegExp('\\W'), '').isEmpty ?? true) {
throw ArgumentError.notNull('environment');
}
headers = {
'api_key': _apiKey,
'access_token': _deliveryToken,
'environment': _environment,
};
if (branch != null && branch.isNotEmpty) {
headers['branch'] = branch;
}
if (livePreview != null && livePreview.isNotEmpty) {
__validateLivePreview();
}
_client = HttpClient(headers, client: client, stack: this);
}