akedly 0.0.3 copy "akedly: ^0.0.3" to clipboard
akedly: ^0.0.3 copied to clipboard

A simple Flutter package for Akedly OTP verification. Provides a clean interface for sending and verifying OTP codes through Akedly's Orchestrating API algorithm for all available channels (WhatsApp, [...]

๐Ÿš€ Akedly Flutter Package #

Pub License Flutter Dart

A simple, elegant Flutter package for Akedly OTP verification. This package provides a clean interface for sending and verifying OTP codes through Akedly's API, abstracting away the complexity of the underlying transaction management.

โœจ Features #

  • ๐ŸŽฏ Simple API: Just two methods - sendOTP() and verifyOTP()
  • ๐Ÿ”„ Automatic Transaction Management: Handles all internal API calls automatically
  • ๐Ÿ›ก๏ธ Robust Error Handling: Comprehensive error handling with meaningful exceptions
  • ๐Ÿ”’ Type Safe: Fully typed with Dart's strong typing system
  • ๐Ÿงช Testable: Supports dependency injection for testing
  • ๐Ÿ“ฑ Flutter Ready: Built specifically for Flutter applications
  • ๐Ÿ“š Well Documented: Complete documentation with examples

๐Ÿš€ Quick Start #

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  akedly: ^0.0.1

Then run:

flutter pub get

Basic Usage #

import 'package:akedly/akedly.dart';

// Initialize the client
final akedlyClient = AkedlyClient(
  apiKey: 'your_api_key_here',
  pipelineId: 'your_pipeline_id_here',
);

// Send OTP
try {
  final verificationId = await akedlyClient.sendOTP('+1234567890');
  print('OTP sent! Verification ID: $verificationId');
} on AkedlyException catch (e) {
  print('Failed to send OTP: ${e.message}');
}

// Verify OTP
try {
  final isValid = await akedlyClient.verifyOTP(verificationId, '123456');
  if (isValid) {
    print('OTP verified successfully! ๐ŸŽ‰');
  } else {
    print('Invalid OTP code');
  }
} on AkedlyException catch (e) {
  print('Failed to verify OTP: ${e.message}');
}

๐Ÿ“– Complete Example #

Here's a complete example showing how to integrate Akedly OTP verification in your Flutter app:

import 'package:flutter/material.dart';
import 'package:akedly/akedly.dart';

class OTPService {
  late final AkedlyClient _client;
  
  OTPService() {
    _client = AkedlyClient(
      apiKey: 'your_api_key_here',
      pipelineId: 'your_pipeline_id_here',
    );
  }
  
  Future<String?> sendOTPToUser(String phoneNumber) async {
    try {
      final verificationId = await _client.sendOTP(phoneNumber);
      return verificationId;
    } on AkedlyException catch (e) {
      print('Error sending OTP: ${e.message}');
      return null;
    }
  }
  
  Future<bool> verifyUserOTP(String verificationId, String otpCode) async {
    try {
      return await _client.verifyOTP(verificationId, otpCode);
    } on AkedlyException catch (e) {
      print('Error verifying OTP: ${e.message}');
      return false;
    }
  }
  
  void dispose() {
    _client.dispose();
  }
}

๐Ÿ”ง API Reference #

AkedlyClient #

The main client class for interacting with the Akedly API.

Constructor

AkedlyClient({
  required String apiKey,
  required String pipelineId,
  http.Client? httpClient,
})

Parameters:

  • apiKey (required): Your Akedly API key
  • pipelineId (required): Your Akedly pipeline ID
  • httpClient (optional): Custom HTTP client for testing purposes

Methods

sendOTP(String phoneNumber)

Sends an OTP to the specified phone number via WhatsApp.

Parameters:

  • phoneNumber: The phone number to send the OTP to (should include country code)

Returns: Future<String> - The verification ID to use in verifyOTP()

Throws: AkedlyException if the API request fails

Example:

final verificationId = await akedlyClient.sendOTP('+1234567890');
verifyOTP(String verificationId, String otp)

Verifies the OTP code entered by the user.

Parameters:

  • verificationId: The verification ID returned from sendOTP()
  • otp: The OTP code entered by the user

Returns: Future<bool> - true if the OTP is valid, false otherwise

Throws: AkedlyException if the API request fails

Example:

final isValid = await akedlyClient.verifyOTP(verificationId, '123456');
dispose()

Closes the HTTP client. Call this when you're done using the client to free up resources.

AkedlyException #

Exception thrown when Akedly API operations fail.

Properties:

  • message: The error message
  • statusCode: The HTTP status code (if available)

Example:

try {
  await akedlyClient.sendOTP('+1234567890');
} on AkedlyException catch (e) {
  print('Error: ${e.message}');
  if (e.statusCode != null) {
    print('Status Code: ${e.statusCode}');
  }
}

๐Ÿ›ก๏ธ Error Handling #

The package provides comprehensive error handling through the AkedlyException class:

try {
  final verificationId = await akedlyClient.sendOTP('+1234567890');
} on AkedlyException catch (e) {
  switch (e.statusCode) {
    case 400:
      print('Bad request: ${e.message}');
      break;
    case 401:
      print('Unauthorized: Check your API key');
      break;
    case 404:
      print('Resource not found: ${e.message}');
      break;
    default:
      print('API error: ${e.message}');
  }
}

๐Ÿงช Testing #

The package supports dependency injection for testing:

import 'package:http/http.dart' as http;

// In your tests
final mockClient = MockClient();
final akedlyClient = AkedlyClient(
  apiKey: 'test_key',
  pipelineId: 'test_pipeline',
  httpClient: mockClient,
);

๐Ÿš€ Getting Started with Akedly #

  1. Sign up at akedly.io
  2. Get your credentials from the dashboard:
    • API Key
    • Pipeline ID
  3. Install the package in your Flutter project
  4. Initialize the client with your credentials
  5. Start sending and verifying OTPs!

๐Ÿ“ฑ Example App #

This package includes a complete example Flutter app demonstrating:

  • ๐Ÿ“ž Phone number input
  • ๐Ÿ“ค OTP sending via WhatsApp/Email
  • ๐Ÿ”ข OTP code input
  • โœ… OTP verification
  • ๐Ÿ“Š Success/error feedback
  • ๐ŸŽจ Beautiful Material Design UI

To run the example:

cd example
flutter pub get
flutter run

Note: Remember to update the API credentials in example/main.dart before running.

๐Ÿ“„ License #

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support #

If you encounter any issues or have questions:

๐Ÿ™ Acknowledgments #

  • Built with โค๏ธ for the Flutter community
  • Powered by Akedly

Made with โค๏ธ by the Akedly Team

1
likes
135
points
29
downloads

Publisher

verified publisherakedly.io

Weekly Downloads

A simple Flutter package for Akedly OTP verification. Provides a clean interface for sending and verifying OTP codes through Akedly's Orchestrating API algorithm for all available channels (WhatsApp, SMS, email & soon, Totp.)

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on akedly