Dart SDK (BETA)

Last updated: Dec-28-2022

Overview

Cloudinary's Dart SDK provides simple, yet comprehensive image and video transformation, optimization, and delivery capabilities that you can implement using code that integrates seamlessly with your existing Dart application.

Important
The Dart SDK is currently in BETA. There may be minor changes to parameter names or other implementation details before the general access release. We invite you to try it out. We would appreciate any feedback via our support team.

Tip
In this guide you'll learn how to get started with the Dart SDK, but if you are not familiar with Cloudinary, we advise reading How to integrate Cloudinary first for a high-level overview of integrating Cloudinary into your code, and an introduction to the main concepts.

Related topics
This guide relates to the latest released version of the Cloudinary Dart library.

Key features

  • Uses Cloudinary's new SDK action based syntax with enhanced code autocomplete.
  • Build dynamic URLs for delivering images and videos.
  • Actions and transformations are immutable, for easier and safer code reuse.

Get started

Install and configure the SDK in your project to get started.

Add the Dart SDK dependency

To use this SDK, add Cloudinary as a dependency in your pubspec.yaml file.

Copy to clipboard
dependencies:
  cloudinary_dart: ^0.0.10

Add your Cloudinary configuration

The Cloudinary class is the main entry point for using the library. Your cloud_name is required to create an instance of this class. Your api_key and api_secret are also needed to perform secure API calls to Cloudinary (e.g., image and video uploads). Setting the configuration parameters can be done either programmatically using an appropriate constructor of the Cloudinary class or globally using an environment variable. You can find your configuration credentials in the Programmable Media Dashboard of the Cloudinary Console.

Here are two examples for setting configuration parameters in your Dart application:

  • Use Cloudinary.fromStringUrl and pass your API environment variable:

    Copy to clipboard
    var cloudinary = Cloudinary.fromStringUrl('cloudinary://<your-api-key>:<your-api-secret>@<your-cloud-name>');

    Define optional configuration parameters by adding them to your configuration file. For example, set the secure optional configuration parameter to true in the configuration file named cloudinary:

    Copy to clipboard
    cloudinary.config.urlConfig.secure = true;

    Note
    The examples in this SDK guide assume you've used the fromStringUrl method of setting configuration parameters.

  • Use Cloudinary.fromCloudName and pass your cloudName:

    Copy to clipboard
    CloudinaryContext.cloudinary = Cloudinary.fromCloudName(cloudName: '<your-cloud-name>');

    Define optional configuration parameters by adding them to your configuration file. For example, set the signUrl optional configuration parameter to true:

    Copy to clipboard
    CloudinaryContext.cloudinary.config.urlConfig.signUrl=true;

Examples

Here's a simple example for generating a Cloudinary image URL, including a resize transformation, using the Dart SDK:

Copy to clipboard
(cloudinary.image('sample.jpg')
  ..transformation(Transformation()
    ..resize(Resize.crop()
      ..width(100)
      ..height(150))))
  .toString();

Simple example

Here's a simple example for generating a Cloudinary video URL, including a resize transformation with boomerang and vignette effects, using the Dart SDK:

Copy to clipboard
 (cloudinary.video('ski_jump')
    ..transformation(Transformation()
      ..effect(Effect.boomerang())
      ..effect(Effect.vignette(30))
      ..resize(Resize.pad()
        ..height(360)
        ..width(480))))
      .toString();

Note
Most transformations can be passed as parameters using Cloudinary's new action based syntax with enhanced code autocomplete. Transformations that aren't yet supported for the new syntax can still be implemented by passing them directly as strings via the ..generic() method of the Dart SDK.

For more information about the Dart SDK syntax, see Syntax overview.

Learn more about transformations

✔️ Feedback sent!

Rate this page: