akedly 0.0.3
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 #
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()
andverifyOTP()
- ๐ 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 keypipelineId
(required): Your Akedly pipeline IDhttpClient
(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 fromsendOTP()
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 messagestatusCode
: 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 #
- Sign up at akedly.io
- Get your credentials from the dashboard:
- API Key
- Pipeline ID
- Install the package in your Flutter project
- Initialize the client with your credentials
- 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:
- ๐ง Email: support@akedly.io
- ๐ Website: akedly.io
- ๐ Documentation: API Documentation
๐ Acknowledgments #
- Built with โค๏ธ for the Flutter community
- Powered by Akedly
Made with โค๏ธ by the Akedly Team