akedly 0.0.3
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.)
🚀 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