nigeriabulksms_sdk 0.1.0
nigeriabulksms_sdk: ^0.1.0 copied to clipboard
A comprehensive Flutter/Dart SDK for the NigeriaBulkSMS API. Send SMS, make voice calls, manage audio files, and retrieve account data with a simple, type-safe interface.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:nigeriabulksms_sdk/nigeriabulksms_sdk.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'NigeriaBulkSMS SDK Test',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TestScreen(),
);
}
}
class TestScreen extends StatefulWidget {
@override
_TestScreenState createState() => _TestScreenState();
}
class _TestScreenState extends State<TestScreen> {
final _usernameController = TextEditingController();
final _passwordController = TextEditingController();
final _messageController = TextEditingController();
final _senderController = TextEditingController();
final _mobileController = TextEditingController();
String _result = '';
bool _isLoading = false;
late NigeriaBulkSMSClient? _client;
@override
void initState() {
super.initState();
_client = null;
}
@override
void dispose() {
_client?.close();
_usernameController.dispose();
_passwordController.dispose();
_messageController.dispose();
_senderController.dispose();
_mobileController.dispose();
super.dispose();
}
void _initializeClient() {
if (_usernameController.text.isNotEmpty &&
_passwordController.text.isNotEmpty) {
_client?.close();
_client = NigeriaBulkSMSClient(
username: _usernameController.text,
password: _passwordController.text,
);
setState(() {
_result = 'Client initialized successfully!';
});
} else {
setState(() {
_result = 'Please enter both username and password';
});
}
}
Future<void> _testSendSMS() async {
if (_client == null) {
setState(() {
_result = 'Please initialize client first';
});
return;
}
if (_messageController.text.isEmpty ||
_senderController.text.isEmpty ||
_mobileController.text.isEmpty) {
setState(() {
_result = 'Please fill in all SMS fields';
});
return;
}
setState(() {
_isLoading = true;
});
try {
final response = await _client!.sms.send(
message: _messageController.text,
sender: _senderController.text,
mobiles: _mobileController.text,
);
setState(() {
_result = 'SMS sent successfully!\n${response.toString()}';
_isLoading = false;
});
} on NigeriaBulkSMSException catch (e) {
setState(() {
_result =
'API Error: ${e.message}${e.code != null ? ' (Code: ${e.code})' : ''}';
_isLoading = false;
});
} catch (e) {
setState(() {
_result = 'Unexpected error: $e';
_isLoading = false;
});
}
}
Future<void> _testGetBalance() async {
if (_client == null) {
setState(() {
_result = 'Please initialize client first';
});
return;
}
setState(() {
_isLoading = true;
});
try {
final response = await _client!.data.getBalance();
setState(() {
_result = 'Balance retrieved successfully!\n${response.toString()}';
_isLoading = false;
});
} on NigeriaBulkSMSException catch (e) {
setState(() {
_result =
'API Error: ${e.message}${e.code != null ? ' (Code: ${e.code})' : ''}';
_isLoading = false;
});
} catch (e) {
setState(() {
_result = 'Unexpected error: $e';
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('NigeriaBulkSMS SDK Test'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Client Configuration',
style: Theme.of(context).textTheme.headlineSmall,
),
SizedBox(height: 16),
TextField(
controller: _usernameController,
decoration: InputDecoration(
labelText: 'Username',
border: OutlineInputBorder(),
),
),
SizedBox(height: 8),
TextField(
controller: _passwordController,
decoration: InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
),
obscureText: true,
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _initializeClient,
child: Text('Initialize Client'),
),
SizedBox(height: 32),
Text(
'SMS Test',
style: Theme.of(context).textTheme.headlineSmall,
),
SizedBox(height: 16),
TextField(
controller: _messageController,
decoration: InputDecoration(
labelText: 'Message',
border: OutlineInputBorder(),
),
maxLines: 3,
),
SizedBox(height: 8),
TextField(
controller: _senderController,
decoration: InputDecoration(
labelText: 'Sender ID',
border: OutlineInputBorder(),
),
),
SizedBox(height: 8),
TextField(
controller: _mobileController,
decoration: InputDecoration(
labelText: 'Mobile Number (e.g., 2348030000000)',
border: OutlineInputBorder(),
),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _isLoading ? null : _testSendSMS,
child:
_isLoading ? CircularProgressIndicator() : Text('Send SMS'),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _isLoading ? null : _testGetBalance,
child: _isLoading
? CircularProgressIndicator()
: Text('Get Balance'),
),
SizedBox(height: 32),
Text(
'Result',
style: Theme.of(context).textTheme.headlineSmall,
),
SizedBox(height: 16),
Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8),
color: Colors.grey[50],
),
child: Text(
_result.isEmpty ? 'No results yet' : _result,
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
),
),
),
],
),
),
),
);
}
}