SMS Screen Modifiaction
This commit is contained in:
@@ -151,41 +151,49 @@
|
||||
import 'package:simcards/simcards.dart';
|
||||
|
||||
// This enum provides detailed status back to the UI layer.
|
||||
enum PermissionStatusResult { granted, denied, permanentlyDenied }
|
||||
enum PermissionStatusResult { granted, denied, permanentlyDenied, restricted }
|
||||
|
||||
class SmsService {
|
||||
final Simcards _simcards = Simcards();
|
||||
|
||||
/// Handles the requesting of SMS and Phone permissions.
|
||||
/// Returns a detailed status: granted, denied, or permanentlyDenied.
|
||||
Future<PermissionStatusResult> handleSmsPermission() async {
|
||||
var smsStatus = await Permission.sms.status;
|
||||
var phoneStatus = await Permission.phone.status;
|
||||
Future<PermissionStatusResult> handleSmsPermission() async {
|
||||
var smsStatus = await Permission.sms.status;
|
||||
var phoneStatus = await Permission.phone.status;
|
||||
|
||||
// Check if permissions are already granted
|
||||
if (smsStatus.isGranted && phoneStatus.isGranted) {
|
||||
return PermissionStatusResult.granted;
|
||||
}
|
||||
|
||||
// Check if they have been permanently denied
|
||||
if (smsStatus.isPermanentlyDenied || phoneStatus.isPermanentlyDenied) {
|
||||
return PermissionStatusResult.permanentlyDenied;
|
||||
}
|
||||
|
||||
// If not granted and not permanently denied, request them
|
||||
print("Requesting SMS and Phone permissions...");
|
||||
await [Permission.phone, Permission.sms].request();
|
||||
|
||||
// Re-check status after the request attempt
|
||||
smsStatus = await Permission.sms.status;
|
||||
phoneStatus = await Permission.phone.status;
|
||||
|
||||
if (smsStatus.isGranted && phoneStatus.isGranted) {
|
||||
return PermissionStatusResult.granted;
|
||||
} else {
|
||||
return PermissionStatusResult.denied;
|
||||
}
|
||||
// Check initial status
|
||||
if (smsStatus.isGranted && phoneStatus.isGranted) {
|
||||
return PermissionStatusResult.granted;
|
||||
}
|
||||
if (smsStatus.isPermanentlyDenied || phoneStatus.isPermanentlyDenied) {
|
||||
return PermissionStatusResult.permanentlyDenied;
|
||||
}
|
||||
if (smsStatus.isRestricted || phoneStatus.isRestricted) {
|
||||
return PermissionStatusResult.restricted;
|
||||
}
|
||||
|
||||
// Request permissions if not granted
|
||||
print("Requesting SMS and Phone permissions...");
|
||||
await [Permission.phone, Permission.sms].request();
|
||||
|
||||
// Re-check status after request
|
||||
smsStatus = await Permission.sms.status;
|
||||
phoneStatus = await Permission.phone.status;
|
||||
|
||||
if (smsStatus.isGranted && phoneStatus.isGranted) {
|
||||
return PermissionStatusResult.granted;
|
||||
}
|
||||
if (smsStatus.isPermanentlyDenied || phoneStatus.isPermanentlyDenied) {
|
||||
return PermissionStatusResult.permanentlyDenied;
|
||||
}
|
||||
if (smsStatus.isRestricted || phoneStatus.isRestricted) {
|
||||
return PermissionStatusResult.restricted;
|
||||
}
|
||||
|
||||
// If none of the above, it's denied
|
||||
return PermissionStatusResult.denied;
|
||||
}
|
||||
|
||||
/// Tries to send a single verification SMS.
|
||||
/// This should only be called AFTER permissions have been granted.
|
||||
|
||||
@@ -15,7 +15,6 @@ import 'di/injection.dart';
|
||||
import 'features/auth/controllers/auth_cubit.dart';
|
||||
import 'features/card/screens/card_management_screen.dart';
|
||||
import 'features/auth/screens/splash_screen.dart';
|
||||
import 'features/auth/screens/login_screen.dart';
|
||||
import 'features/service/screens/service_screen.dart';
|
||||
import 'features/dashboard/screens/dashboard_screen.dart';
|
||||
import 'features/auth/screens/mpin_screen.dart';
|
||||
|
||||
@@ -41,42 +41,68 @@
|
||||
while (!hasPermission) {
|
||||
final status = await _smsService.handleSmsPermission();
|
||||
|
||||
switch (status) {
|
||||
case PermissionStatusResult.granted:
|
||||
_showSnackBar("Permissions Granted! Proceeding...");
|
||||
hasPermission = true; // This will break the loop
|
||||
break;
|
||||
case PermissionStatusResult.denied:
|
||||
_showSnackBar("SMS and Phone permissions are required. Please try again.");
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
break;
|
||||
case PermissionStatusResult.permanentlyDenied:
|
||||
if (mounted) {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Permission Required"),
|
||||
content: const Text("SMS and Phone permissions are required for device verification. Please enable them in your app settings to continue."),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text("Cancel"),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("Open Settings"),
|
||||
onPressed: () {
|
||||
openAppSettings(); // Opens the phone's settings screen for this app
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
// Wait for user to return from settings
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
break;
|
||||
}
|
||||
switch (status) {
|
||||
case PermissionStatusResult.granted:
|
||||
_showSnackBar("Permissions Granted! Proceeding...");
|
||||
hasPermission = true; // This will break the loop
|
||||
break;
|
||||
case PermissionStatusResult.denied:
|
||||
_showSnackBar("SMS and Phone permissions are required. Please try again.");
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
break;
|
||||
case PermissionStatusResult.permanentlyDenied:
|
||||
if (mounted) {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Permission Required"),
|
||||
content: const Text("SMS and Phone permissions are required for device verification. Please enable them in your app settings to continue."),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text("Cancel"),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("Open Settings"),
|
||||
onPressed: () {
|
||||
openAppSettings(); // Opens the phone's settings screen for this app
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
// Wait for user to return from settings
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
break;
|
||||
case PermissionStatusResult.restricted:
|
||||
if (mounted) {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Permission Restricted"),
|
||||
content: const Text(
|
||||
"SMS and Phone permissions are restricted on this device. Please check your device settings or parental controls and enable them for this app."),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text("Cancel"),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("Open Settings"),
|
||||
onPressed: () {
|
||||
openAppSettings();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// --- SMS SENDING LOOP ---
|
||||
|
||||
@@ -37,7 +37,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
final storage = getIt<SecureStorage>();
|
||||
final isEnabled = await storage.read('biometric_enabled');
|
||||
setState(() {
|
||||
_isBiometricEnabled = isEnabled == 'true';
|
||||
_isBiometricEnabled = isEnabled == true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user