easy2sms_otp 1.0.0
easy2sms_otp: ^1.0.0 copied to clipboard
A powerful and easy-to-use Flutter package for sending and verifying OTPs using the Easy2SMS API. Supports customizable OTP length, custom message templates, and delivery status tracking.
easy2sms_otp #
A Flutter package for sending and verifying OTPs using the Easy2SMS API.
Features #
- Send OTP to any mobile number.
- Customizable OTP length.
- Support for custom message templates.
- Verify OTP locally.
- Check delivery status of the sent SMS.
Getting started #
Add easy2sms_otp to your pubspec.yaml:
dependencies:
easy2sms_otp:
path: ../easy2sms_otp # If using locally
Platform Configuration #
Since this package uses a raw IP address and http (not https), you must configure your projects to allow cleartext (non-secure) traffic.
Android #
- Add Internet permission to your
AndroidManifest.xml(usually inandroid/app/src/main/AndroidManifest.xml):
<uses-permission android:name="android.permission.INTERNET" />
- Allow cleartext traffic:
<application
...
android:usesCleartextTraffic="true">
iOS #
Add the following to your ios/Runner/Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Web #
No specific configuration is needed in the Flutter code. However, due to browser CORS policies, you might face issues during local development.
For testing on Web locally: Run your project using the following command to bypass CORS:
flutter run -d chrome --web-browser-flag "--disable-web-security"
Note: In production, ensure your API server (135.181.75.92) is configured to allow requests from your web domain.
Usage #
Initialize the package #
final easy2sms = Easy2SMSOTP(
authKey: 'YOUR_AUTH_KEY',
templateId: 'YOUR_TEMPLATE_ID',
senderId: 'ITTHNK', // Default is ITTHNK
);
Send OTP #
String? msgId = await easy2sms.sendOTP(number: '8059290641');
if (msgId != null) {
print('OTP sent successfully. Message ID: $msgId');
} else {
print('Failed to send OTP');
}
Verify OTP #
bool isValid = easy2sms.verifyOTP('12345');
if (isValid) {
print('OTP Verified!');
} else {
print('Invalid OTP');
}
Check Delivery Status #
String? status = await easy2sms.checkStatus(msgId!);
print('Delivery Status: $status');
Additional information #
The API endpoint used is http://135.181.75.92/.
Ensure your templateid and message match the DLT registration requirements.