💙

Flutter SDK

Official SDK for Flutter and Dart applications.

Installation

Add to your pubspec.yaml:

dependencies:
  notification_system_sdk: ^1.0.0

Then run:

flutter pub get

Requirements

  • • Dart 2.17 or later
  • • Flutter 3.0 or later

Quick Start

import 'package:notification_system_sdk/notification_system_sdk.dart';

void main() async {
  // Initialize client
  final client = NotificationClient(ClientConfig(
    apiKey: const String.fromEnvironment('NOTIFICATION_API_KEY'),
  ));

  // Send notification
  final response = await client.sendNotification(NotificationRequest(
    channels: [NotificationChannel.email, NotificationChannel.sms],
    content: 'Hello World!',
    targets: ['user@example.com', '+1234567890'],
  ));

  print('Notification ID: ${response.id}');
  print('Status: ${response.status}');
}

Configuration

final client = NotificationClient(ClientConfig(
  apiKey: 'ntf_your_api_key',
  baseUrl: 'https://api.notifications.example.com/v1',
  timeout: const Duration(seconds: 30),
  retries: 3,
));

API Methods

client.sendNotification(NotificationRequest request)

Send a notification to one or more channels.

final response = await client.sendNotification(NotificationRequest(
  channels: [
    NotificationChannel.email,
    NotificationChannel.sms,
    NotificationChannel.slack,
  ],
  content: 'Your order has been shipped!',
  targets: ['user@example.com', '+1234567890', '#orders'],
  metadata: {'orderId': '12345'},
));
client.getNotification(String id)

Get details of a specific notification.

final notification = await client.getNotification('ntf_abc123');
print('Status: ${notification.status}');
client.listNotifications({int? page, int? perPage, String? status, String? channel})

List notifications with pagination and filters.

final result = await client.listNotifications(
  page: 1,
  perPage: 20,
  status: 'delivered',
  channel: 'email',
);

for (final notification in result.notifications) {
  print('ID: ${notification.id}, Status: ${notification.status}');
}
client.createIntegration(String projectId, {required String name, required String platformType})

Create a platform integration with separate API keys.

final integration = await client.createIntegration(
  'project-id',
  name: 'Production Mobile App',
  platformType: 'mobile',
  sdkLanguage: 'flutter',
);
client.createApiKey(String integrationId, {String? description})

Create an API key scoped to one platform integration.

final key = await client.createApiKey(
  integration.id,
  description: 'Flutter app key',
);
print(key.key);

Error Handling

try {
  final response = await client.sendNotification(request);
} on ApiException catch (e) {
  print('API error: ${e.message} (status: ${e.statusCode})');
} on NetworkException catch (e) {
  print('Network error: ${e.message}');
} catch (e) {
  print('Unexpected error: $e');
}

Flutter Widget Example

Use in a Flutter widget:

class NotificationButton extends StatefulWidget {
  @override
  _NotificationButtonState createState() => _NotificationButtonState();
}

class _NotificationButtonState extends State<NotificationButton> {
  final _client = NotificationClient(ClientConfig(
    apiKey: const String.fromEnvironment('NOTIFICATION_API_KEY'),
  ));

  bool _loading = false;

  Future<void> _sendNotification() async {
    setState(() => _loading = true);

    try {
      await _client.sendNotification(NotificationRequest(
        channels: [NotificationChannel.email],
        content: 'Test notification from Flutter!',
        targets: ['user@example.com'],
      ));

      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Notification sent!')),
      );
    } catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Error: $e')),
      );
    } finally {
      setState(() => _loading = false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: _loading ? null : _sendNotification,
      child: _loading
          ? const CircularProgressIndicator()
          : const Text('Send Notification'),
    );
  }
}