CastBricks Docs

Dart / Flutter SDK

Install and use the official CastBrick Dart SDK

Dart / Flutter SDK

castbrick is the official Dart SDK. Works in any Dart or Flutter project — mobile, web, desktop, and server.

Installation

dart pub add castbrick
# or for Flutter:
flutter pub add castbrick

Initialization

import 'package:castbrick/castbrick.dart';

final cb = CastBrick(apiKey: Platform.environment['CASTBRICK_API_KEY']!);

// Remember to close when done
cb.close();

SMS

Send

final result = await cb.sms.send(
  to: ['+244923000000', '+244912000000'],
  content: 'Your verification code is 1234',
  senderId: 'MyApp', // optional
);

print('${result.messageId}${result.status}');

Schedule for later

await cb.sms.send(
  to: ['+244923000000'],
  content: 'Scheduled message',
  scheduledAt: DateTime.now().toUtc().add(Duration(hours: 2)),
);

List / Get / Cancel

final page = await cb.sms.list(page: 1, pageSize: 20);
print(page.totalCount);

final msg = await cb.sms.get('message-id');
print(msg.status);

await cb.sms.cancelScheduled('message-id');

Contacts

// List (with optional search)
final page = await cb.contacts.list(search: 'joão');

// Get
final contact = await cb.contacts.get('contact-id');

// Create (comma-separated phone numbers)
await cb.contacts.create(phoneNumbers: '+244923000000,+244912000000');

// Delete
await cb.contacts.delete('contact-id');

// Contact lists
final list = await cb.contacts.createList('VIP Customers');
await cb.contacts.addToList(list.id, contact.id);
await cb.contacts.removeFromList(list.id, contact.id);

Broadcasts

// Create
final id = await cb.broadcasts.create(
  name: 'Black Friday',
  message: '50% off everything today!',
  contactListId: listId,  // optional
  senderId: 'MyApp',      // optional
);

// Send immediately
await cb.broadcasts.send(id);

// Update with schedule
await cb.broadcasts.update(
  id,
  name: 'Black Friday',
  message: '50% off everything today!',
  scheduleAt: DateTime(2026, 11, 28, 9, 0).toUtc(),
);

// Other operations
await cb.broadcasts.cancel(id);
final newId = await cb.broadcasts.duplicate(id);
await cb.broadcasts.delete(id);

Error Handling

try {
  await cb.sms.send(to: ['+244923000000'], content: 'Hello!');
} on CastBrickApiError catch (e) {
  print('${e.status}: ${e.body}');
  // 401 → invalid or revoked API key
  // 402 → insufficient credits
  // 422 → validation error
}