129 lines
3.6 KiB
Dart
129 lines
3.6 KiB
Dart
// // ignore_for_file: avoid_print
|
|
// import 'dart:io';
|
|
// import 'package:flutter/material.dart';
|
|
// import 'send_sms.dart';
|
|
// import 'package:simcards/sim_card.dart';
|
|
// import 'package:simcards/simcards.dart';
|
|
|
|
// import 'package:uuid/uuid.dart';
|
|
|
|
// class SmsService {
|
|
// final Simcards _simcards = Simcards();
|
|
|
|
// Future<void> sendVerificationSms({
|
|
// required BuildContext context,
|
|
// required String destinationNumber,
|
|
// required String message,
|
|
// }) async {
|
|
// try {
|
|
// await _simcards.requestPermission();
|
|
|
|
// bool permissionGranted = await _simcards.hasPermission();
|
|
// if (!permissionGranted) {
|
|
// print("Permission denied." );
|
|
// return;
|
|
// }
|
|
|
|
// List<SimCard> simCardList = await _simcards.getSimCards();
|
|
// if (simCardList.isEmpty) {
|
|
// print("No SIM detected." );
|
|
// return;
|
|
// }
|
|
|
|
// await _sendSms(destinationNumber, message, simCardList.first);
|
|
|
|
// } catch (e) {
|
|
// print("Error in SMS process: $e");
|
|
// }
|
|
// }
|
|
|
|
|
|
// Future<void> _sendSms(
|
|
// String destinationNumber, String message, SimCard selectedSim) async {
|
|
// if (Platform.isAndroid) {
|
|
// try {
|
|
// var uuid = const Uuid();
|
|
// String uniqueId = uuid.v4();
|
|
|
|
// String smsMessage = uniqueId;
|
|
// String result = await sendSMS(
|
|
// message: smsMessage,
|
|
// recipients: [destinationNumber],
|
|
// sendDirect: true,
|
|
// );
|
|
// print("SMS send result: $result. Sent via ${selectedSim.displayName} (Note: OS default SIM isused).");
|
|
|
|
// } catch (e) {
|
|
// print("Error sending SMS: $e");
|
|
// }
|
|
// } else {
|
|
// print("SMS sending is only supported on Android.");
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// ignore_for_file: avoid_print
|
|
import 'dart:io';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_sms/flutter_sms.dart'; // <-- 1. IMPORT the new package
|
|
import 'package:simcards/sim_card.dart';
|
|
import 'package:simcards/simcards.dart';
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
class SmsService {
|
|
final Simcards _simcards = Simcards();
|
|
|
|
Future<void> sendVerificationSms({
|
|
required BuildContext context,
|
|
required String destinationNumber,
|
|
required String message,
|
|
}) async {
|
|
try {
|
|
await _simcards.requestPermission();
|
|
|
|
bool permissionGranted = await _simcards.hasPermission();
|
|
if (!permissionGranted) {
|
|
print("Permission denied.");
|
|
return;
|
|
}
|
|
|
|
List<SimCard> simCardList = await _simcards.getSimCards();
|
|
if (simCardList.isEmpty) {
|
|
print("No SIM detected.");
|
|
return;
|
|
}
|
|
|
|
await _sendSms(destinationNumber, message, simCardList.first);
|
|
} catch (e) {
|
|
print("Error in SMS process: $e");
|
|
}
|
|
}
|
|
|
|
Future<void> _sendSms(
|
|
String destinationNumber, String message, SimCard selectedSim) async {
|
|
if (Platform.isAndroid) {
|
|
try {
|
|
var uuid = const Uuid();
|
|
String uniqueId = uuid.v4();
|
|
|
|
String smsMessage = uniqueId;
|
|
|
|
// v-- 2. UPDATE the function call below --v
|
|
String result = await sendSMS(
|
|
message: smsMessage,
|
|
recipients: [destinationNumber],
|
|
);
|
|
// ^-- The 'sendDirect' parameter is not available in this package. --^
|
|
// It will open the user's default messaging app with the fields pre-filled.
|
|
|
|
print(
|
|
"SMS send result: $result. Sent via ${selectedSim.displayName} (Note: OS default SIM isused)."
|
|
);
|
|
} catch (e) {
|
|
print("Error sending SMS: $e");
|
|
}
|
|
} else {
|
|
print("SMS sending is only supported on Android.");
|
|
}
|
|
}
|
|
} |