Chilkat for Dart and Flutter — the chilkat package
Chilkat for Dart is the chilkat package on
pub.dev: one class per Chilkat class (CkHttp, CkJsonObject, …), Dart getters and
setters for properties, exceptions for failures, and progress events as callback properties. It works in Flutter apps
on Android, iOS, macOS, Windows and Linux, and in Dart command-line and server programs. HTTP and REST, email (SMTP,
POP3, IMAP, MIME), FTP, SFTP, SSH, zip and compression, encryption, digital signatures, certificates, XML, JSON,
sockets and more — the same functionality as every other Chilkat product.
Jump to: Add to your project · Quick start · Supported targets · Flutter and long-running calls · Offline builds · How the API maps to Dart · Licensing
Documentation & Samples
- 📖 Chilkat Dart Reference Documentation — every class, method and property with its Dart signature
- 💻 Chilkat Dart Sample Code — ready-to-run examples
- 📦 chilkat on pub.dev · API docs (dartdoc) on pub.dev
- 📝 Release Notes on the Chilkat blog
Add to your project
dart pub add chilkat # or: flutter pub add chilkat
or add the dependency to pubspec.yaml by hand:
dependencies: chilkat: ^11.6.1
Then build or run as usual (dart run, flutter run, flutter build). On
the first build the package's build hook downloads
chilkat-dart-<os>-<arch>.tar.gz for your target from
https://chilkatdownload.com/<version>/, checks its SHA-256 against the table
compiled into the package, unpacks it into the build cache, and bundles the shared library with your application
(libchilkat_c_bridge.so, libchilkat_c_bridge.dylib or
chilkat_c_bridge.dll). Later builds reuse the cached, verified copy, so the download
happens once per Chilkat version per target. A Flutter app that targets several platforms gets the library for each
one automatically.
dart:ffi). No C or
C++ compiler is needed on any platform — the Chilkat library ships prebuilt. Web (dart2js / Wasm) is not
supported, since the library is native code.
Quick start
import 'package:chilkat/chilkat.dart';
void main() {
// Any string unlocks the fully functional 30-day trial. Call once per isolate.
Chilkat.unlockBundle('Anything for 30-day trial');
final http = CkHttp();
http.connectTimeout = 30;
http.setRequestHeader('Accept', 'application/json');
try {
final body = http.quickGetStr('https://api.github.com/repos/dart-lang/sdk');
final json = CkJsonObject();
json.load(body);
print('${json.intOf('stargazers_count')} stars');
} on ChilkatException catch (e) {
print(e); // CkHttp.quickGetStr failed: <reason>
print(e.lastErrorText); // the full Chilkat log of the failed call
}
}
A method that can fail throws ChilkatException instead of returning a status. The exception carries
the object's LastErrorText from the moment of the failure (e.lastErrorText), the class and
method names, and a one-line message. Objects release their native resources when garbage collected;
call dispose() to release them immediately (a large CkBinData, an open socket).
Supported targets
A prebuilt Chilkat shared library is published for each of these targets with every Chilkat release. The archive is what the build hook downloads; the name is chilkat-dart-<os>-<arch>[-simulator].tar.gz.
| Platform | Archive | Notes |
|---|---|---|
| Android | chilkat-dart-android-arm64.tar.gz | arm64-v8a, armeabi-v7a and x86_64 (the x86_64 build is for emulators). Android 7.0 (API 24) or later; 16 KB page sizes supported. |
| chilkat-dart-android-arm.tar.gz | ||
| chilkat-dart-android-x64.tar.gz | ||
| iOS | chilkat-dart-ios-arm64.tar.gz | Devices, and the simulator on Apple silicon and Intel Macs. The library is a code-signed dynamic library; Flutter embeds it in the app bundle. |
| chilkat-dart-ios-arm64-simulator.tar.gz | ||
| chilkat-dart-ios-x64-simulator.tar.gz | ||
| macOS | chilkat-dart-macos.tar.gz | One universal library (Apple silicon and Intel). |
| Windows | chilkat-dart-windows-x64.tar.gz | x64 and ARM64. Windows 10 or later. |
| chilkat-dart-windows-arm64.tar.gz | ||
| Linux | chilkat-dart-linux-x64.tar.gz | x64 and ARM64 (aarch64), glibc-based distributions: Debian/Ubuntu, RHEL/Fedora, SUSE, Arch, Raspberry Pi OS 64-bit, … |
| chilkat-dart-linux-arm64.tar.gz |
The build hook chooses the archive from the target of the build (the platform and architecture
Flutter or dart build is producing), not from the host, so cross-building for Android or iOS from a
desktop works the same way. A target not in this table fails the build with a message naming the supported
targets; if you need another one, contact Chilkat support.
Flutter and long-running calls
Every Chilkat call is synchronous and blocks the calling isolate. Quick operations (JSON, XML, hashing, encoding) are fine on the UI isolate; network and large file operations belong in a worker isolate so the UI stays responsive. Chilkat objects cannot be sent between isolates, so the worker creates its own:
final body = await Isolate.run(() {
final http = CkHttp()..connectTimeout = 30;
return http.quickGetStr(url);
});
Progress and cancellation: the event-capable classes (CkHttp, CkFtp2,
CkSFtp, CkZip, CkImap, …) have onPercentDone,
onProgressInfo and onAbortCheck callback properties. They fire on the calling thread,
inside the method call; return true from onPercentDone or onAbortCheck to
abort. From a worker isolate, forward progress to the UI through a SendPort:
final progress = ReceivePort();
progress.listen((pct) => setState(() => _pct = pct as int));
await Isolate.run(() {
final ftp = CkFtp2()..hostname = host ..username = user ..password = pw;
ftp.onPercentDone = (pct) { progress.sendPort.send(pct); return false; };
ftp.connect();
ftp.getFile('remote.dat', localPath);
});
The *Async methods, Task and TaskChain of other Chilkat products are not part of the Dart package; isolates are the Dart way to run work in the background.
Offline builds, vendoring, and your own Chilkat library
Build machines without internet access, or that must not download during a build, point the build hook at
a library directory instead. Build hooks do not see the caller's environment variables, so the setting is a
user-define in the application's pubspec.yaml (the root package of the build, not a
library package it depends on):
hooks:
user_defines:
chilkat:
lib_dir: /opt/chilkat/lib # the directory containing libchilkat_c_bridge.so,
# libchilkat_c_bridge.dylib or chilkat_c_bridge.dll;
# a relative path resolves against this pubspec.yaml
With lib_dir set, nothing is downloaded. To populate that directory, download the archive for
your target once from a connected machine and unpack it — the URL is
https://chilkatdownload.com/<version>/chilkat-dart-<os>-<arch>.tar.gz
# for example, for chilkat 11.6.1 on 64-bit Linux:
https://chilkatdownload.com/11.6.1/chilkat-dart-linux-x64.tar.gz
where <version> is the exact version of the chilkat package you
depend on (shown on pub.dev and in pubspec.lock).
Each archive contains the shared library, license.pdf, a software bill of materials,
and a VERSION file. The SHA-256 of every published archive is listed in
lib/src/checksums.dart inside the package of the same version.
All build-hook settings (user-defines under hooks: user_defines: chilkat:):
| User-define | Effect |
|---|---|
| lib_dir | Directory containing the Chilkat shared library for the target. When set, nothing is downloaded. Also the way to build against your own CBridge build of the Chilkat C++ library. |
| cache_dir | Where downloaded archives are unpacked and reused, instead of the build's shared output directory. Useful on CI to keep the cache between jobs. The archives are cached per Chilkat version. |
| download_base | Base URL to download from, instead of https://chilkatdownload.com — for an internal mirror that serves the same <version>/chilkat-dart-<os>-<arch>.tar.gz paths. The SHA-256 check still applies. |
A checksum mismatch fails the build rather than bundling an unverified library. (The environment variables CHILKAT_DART_LIB_DIR, CHILKAT_DART_CACHE_DIR and CHILKAT_DOWNLOAD_BASE are honoured too, but only by a hook runner that passes the environment through, which the standard Dart and Flutter tooling does not.)
How the Chilkat API maps to Dart
| Chilkat | Dart |
|---|---|
| Class Http, JsonObject, CkDateTime | CkHttp, CkJsonObject, CkDateTime — every class has a Ck prefix and is created with CkHttp(). Released by the garbage collector, or at once with dispose(). |
| Property ConnectTimeout | http.connectTimeout getter and setter |
| Method QuickGetStr, S3_DownloadFile | quickGetStr(), s3DownloadFile() — lowerCamelCase, same arguments |
| Method returning success/failure (bool) | returns void; throws ChilkatException on failure |
| Method returning a string or an object (null on failure) | returns String, CkCert, …; throws ChilkatException when Chilkat returns null |
| Method answering a question (HasMember, IsUnlocked, TagEquals, …) | plain bool |
| LastErrorText | obj.lastErrorText, and e.lastErrorText on the exception |
| Byte arrays | Uint8List (and CkBinData for large or repeatedly used data) |
| Events (AbortCheck, PercentDone, ProgressInfo) | Callback properties: obj.onAbortCheck = () { ... }, obj.onPercentDone = (pct) { ... }, obj.onProgressInfo = (name, value) { ... } |
| *Async methods, Task, TaskChain | Not included. Chilkat calls are synchronous; run them in a worker isolate (Isolate.run). |
| UnlockBundle (the Global class) | Chilkat.unlockBundle(code) — a static shorthand for CkGlobal().unlockBundle(code); once per isolate |
The reference documentation shows the exact Dart signature of every member, and the same text is available as dartdoc in your IDE.
Licensing
This is the full-version Chilkat product. Chilkat libraries are
fully functional for a 30-day evaluation; passing any
non-empty string to Chilkat.unlockBundle starts the trial, and a purchased unlock code removes the time
limit. The license terms are in the LICENSE file of the package (and
license.pdf in every native archive). For questions, see the
reference documentation or
contact Chilkat support.