Dart quick start
Last updated: Mar-27-2025
This quick start lets you get an end-to-end implementation up and running using the Dart SDK in 5 minutes or less.
Prerequisites
1. Set up and configure the SDK
Install the package
Install the @cloudinary_url_gen
package by adding Cloudinary as a dependency in your pubspec.yaml file.
dependencies:
cloudinary_url_gen: ^1.0.0
cloudinary_api: ^1.0.0
Configure Cloudinary
In your main.dart
file, configure your credentials using your API environment variable. Copy the API environment variable format from the API Keys page of the Cloudinary Console Settings. Replace <your_api_key>
and <your_api_secret>
with your actual values. Your cloud name is already correctly included in the format.
// Import the Cloudinary packages.
import 'package:cloudinary_url_gen/cloudinary.dart';
import 'package:cloudinary_url_gen/transformation/transformation.dart';
import 'package:cloudinary_api/uploader/cloudinary_uploader.dart';
import 'package:cloudinary_api/src/request/model/uploader_params.dart';
import 'package:cloudinary_url_gen/transformation/effect/effect.dart';
import 'package:cloudinary_url_gen/transformation/resize/resize.dart';
// Create a Cloudinary instance and set your cloud name.
var cloudinary=Cloudinary.fromStringUrl('cloudinary://API_KEY:API_SECRET@CLOUD_NAME');
void main() async{
cloudinary.config.urlConfig.secure = true;
await upload();
transform();
}
2. Upload an image
Copy and paste this into main.dart
:
upload() async{
var response = await cloudinary.uploader().upload('https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpeg',
params: UploadParams(
publicId: 'quickstart_butterfly',
uniqueFilename: false,
overwrite: true));
print("Public ID:");
print(response?.data?.publicId);
print("Secure URL:");
print(response?.data?.secureUrl);
}
3. Transform the image
Generate a delivery URL for the uploaded image with the desired transformation applied.
Copy and paste the following code, under the configuration code:
transform() {
// Generate a delivery URL for the uploaded image with the desired transformation applied.
String url = (cloudinary.image('quickstart_butterfly')
..transformation(Transformation()
..resize(Resize.fill()
..width(250)
..height(250))
..effect(Effect.sepia())))
.toString();
print("Secure URL with Transformation:");
print(url);
}
4. Run your code
Run the code with dart run main.dart
to see the transformed image.
View the completed code
This code is available on GitHub.
- Understand the architecture of the Dart SDK and get a more detailed overview of the libraries.
- Find out more about transforming images and videos using
@cloudinary_url_gen
. - View a comprehensive listing of all available transformations with syntax details and examples in the transformation reference.