contentstack 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

Contentstack #

Dart SDK for Contentstack #

Coverage Dart CI

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.

Contentstack provides Dart SDK to build application on top of Dart. Given below is the detailed guide and helpful resources to get started with our Dart SDK.

Prerequisite #

You will need Dart installed on your machine. You can install it from here.

Setup and Installation #

To use the Contentstack Dart SDK to your existing project, perform the steps given below:

Install Dart Package

dependencies:
  contentstack: any

Key Concepts for using Contentstack #

Stack

A stack is like a container that holds the content of your app. Learn more about Stacks.

Content Type

Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. Read more.

Entry

An entry is the actual piece of content created using one of the defined content types. Learn more about Entries.

Asset

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about Assets.

Environment

A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with Environments.

Contentstack Dart SDK: 5-minute Quickstart #

Initializing your SDK

To initialize the SDK, specify application API key, access token, and environment name of the stack as shown in the snippet given below (config is optional):

import 'package:contentstack/contentstack.dart' as contentstack;

final stack = Contentstack.stack(apiKey, deliveryToken, environment);

To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings & Stack to view the API Key and Access Token.

Querying content from your stack

To retrieve a single entry from a content type use the code snippet given below:

import 'package:contentstack/contentstack.dart' as contentstack;

final stack = contentstack.Stack(apiKey, deliveryToken, environment);
final entry = stack.contentType('contentTypeUid').entry(entryUid: 'entryUid');
    await entry.fetch().then((response) {
        print(response.toString());
    }).catchError((error) {
        print(error.message.toString());
    });

Get Multiple Entries

To retrieve multiple entries of a particular content type, use the code snippet given below:

import 'package:contentstack/contentstack.dart' as contentstack;

final stack = contentstack.Stack(apiKey, deliveryToken, environment);
final query = stack.contentType('contentTypeUid').entry().query();
await query.find().then((response) {
        print(response.toString());
    }).catchError((error) {
        print(error.message.toString());
    });

Advanced Queries #

You can query for content types, entries, assets and more using our dart API Reference. Dart API Reference Doc

Working with Images #

We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.

For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400.

There are several more parameters that you can use for your images.

Read Image Delivery API documentation.

You can use the Image Delivery API functions in this SDK as well. Here are a few examples of its usage in the SDK.

import 'package:contentstack/contentstack.dart' as contentstack;

final stack = contentstack.Stack(apiKey, deliveryToken, environment);
imageTransformation = stack.imageTransform(imageUrl);

#set the image quality to 100
imageParams = {'quality': 100}
final imageUrl = imageTransformation..canvas(imageParams)..getUrl();

#resize the image by specifying width and height
imageParams = {'width': 100, 'height': 100}
final response = imageTransformation..canvas(imageParams)..getUrl();

#enable auto optimization for the image
imageParams = {'auto': 'webp'}
final response = imageTransformation..canvas(imageParams)..getUrl();

The MIT License (MIT) #

MIT License

Copyright (c) 2012 - 2020 Contentstack. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[0.1.0] - Initial release #

May-11-2020 -initial release #

Initial release for the contentstack-dart-sdk for Content Delivery API #


[0.0.1] - Beta release #

May-08-2020 -beta release #

Beta release for the contentstack-dart-sdk for Content Delivery API #


example/example.md

Contentstack Examples #

Developer's Guide #

In order to integrate your Flutter app with Contentstack Dart SDK, follow the steps mentioned below.

Prerequisites #

To get started with Dart SDK, you will need the following:

Creating new project using android studio #

  1. In the IDE, click Create New Project from the Welcome window or File > New > Project from the main IDE window.
  2. Select Flutter in the menu, and click Next.
  3. Enter your desired Project name and Project location.
  4. If you might publish this app, set the company domain.
  5. Click Finish.

Creating new project using Visual Studio Code #

  1. Open the Command Palette (Ctrl+Shift+P (Cmd+Shift+P on macOS)).
  2. Select the Flutter: New Project command and press Enter.
  3. Enter your desired Project name.
  4. Select a Project location.

SDK Installation and Setup #

To integrate your Flutter project with Contentstack, install the pub dependency Use this package as a library

Add this to your package's pubspec.yaml file:

dependencies:
  contentstack: any

You can install packages from the command line: with Flutter:

$ flutter pub get

Import package #

Now in your dart or flutter code, you can use

import 'package:contentstack/contentstack.dart' as contentstack;

Initialize SDK #

To initialize the SDK, specify application context, stack’s API Key, delivery token, and name of the environment where will publish your content, as shown in the snippet below:

import 'package:contentstack/contentstack.dart' as contentstack;

final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

Basic Queries #

To retrieve a single entry from a content type use the code snippet given below:

Make call to get single entry by entry uid #

    final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
    final entry = stack.contentType('content_type_uid').entry(entryUid: 'entry_uid');
    await entry.fetch().then((response) {
      print(response.toString());
    }).catchError((error) {
      print(error.message.toString());
    });

Or, You can get generic objects as well

    final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
    final entry = stack.contentType('content_type_uid').entry(entryUid: 'entry_uid');
    await entry.fetch<EntryModel, Null>().then((response) {
      print(response.title);
    }).catchError((error) {
      print(error.message.toString());
    });

Get Multiple Entries #

To retrieve multiple entries of a particular content type, use the code snippet given below:

    final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
    final query = stack.contentType('content_type_uid').entry().query();
    await query.find().then((response) {
      print(response.toString());
    }).catchError((error) {
      print(error.message.toString());
    });

Or, You can get List of generic objects

    final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
    final query = stack.contentType('content_type_uid').entry().query();
    await query.find<List<EntryModel>, EntryModel>().then((response) {
      print(response.toString());
    }).catchError((error) {
      print(error.message.toString());
    });

Make call to get single asset by asset uid #

      final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
      await stack.asset('asset_uid').fetch().then((response) {
        print(response.toString());
      }).catchError((error) {
        print(error.message.toString());
      });

Or, You can get generic objects as well

      final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
      await stack.asset('asset_uid').fetch<AssetModel, Null>().then((response) {
        print(response.toString());
      }).catchError((error) {
        print(error.message.toString());
      });

Make call to apply query on asset #

    final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
    final assetQuery = stack.assetQuery();
    assetQuery..includeDimension()..relativeUrls();
    await assetQuery.find().then((response) {
      print(response.toString());
    }).catchError((error) {
      print(error.message.toString());
    });

Or, You can get List of generic objects

    final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
    final assetQuery = stack.assetQuery();
    assetQuery..includeDimension()..relativeUrls();
    await assetQuery.find<List<AssetModel>, Null>().then((response) {
      print(response.toString());
    }).catchError((error) {
      print(error.message.toString());
    });

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  contentstack: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:contentstack/contentstack.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because:

  • package:contentstack/contentstack.dart that imports:
  • package:contentstack/src/stack.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:contentstack/contentstack.dart that imports:
  • package:contentstack/src/stack.dart that imports:
  • dart:io

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (dartdoc).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
dartdoc ^0.31.0 0.31.0 0.32.1
http >=0.11.3 <0.13.0 0.12.1
http_parser ^3.0.0 3.1.4
json_annotation ^3.0.1 3.0.1
logger ^0.9.1 0.9.1
super_enum ^0.4.2 0.4.2
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.12
args 1.6.0
async 2.4.2
charcode 1.1.3
cli_util 0.1.4 0.2.0
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
equatable 1.2.2
file 5.2.1
glob 1.2.0
html 0.14.0+3
intl 0.16.1
js 0.6.2
logging 0.11.4
markdown 2.1.5
matcher 0.12.8
meta 1.2.2 1.3.0-nullsafety
mustache 1.1.1
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.2
platform 2.2.1
process 3.0.13
pub_semver 1.4.4
quiver 2.1.3
resource 2.1.7
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner any
build_test ^0.10.0
build_web_compilers >=1.2.0 <3.0.0
json_serializable any
lint ^1.1.1
linter ^0.1.112
super_enum_generator any
test >=0.6.0 <1.11.0
test_coverage ^0.4.1