Florian Griffon
e05880c9d8
All checks were successful
/ mirror (push) Successful in 4s
Reviewed-on: #19 Co-authored-by: Florian Griffon <florian.griffon@epitech.eu> Co-committed-by: Florian Griffon <florian.griffon@epitech.eu>
53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class BlockService {
|
|
static final BlockService _instance = BlockService._internal();
|
|
|
|
factory BlockService() {
|
|
return _instance;
|
|
}
|
|
|
|
BlockService._internal();
|
|
|
|
// Function to add a number to the blocked list
|
|
Future<void> blockNumber(String number) async {
|
|
if (number.isEmpty) return;
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
List<String> blockedNumbers = prefs.getStringList('blockedNumbers') ?? [];
|
|
|
|
if (!blockedNumbers.contains(number)) {
|
|
blockedNumbers.add(number);
|
|
await prefs.setStringList('blockedNumbers', blockedNumbers);
|
|
print('$number has been blocked');
|
|
} else {
|
|
print('$number is already blocked');
|
|
}
|
|
}
|
|
|
|
// Function to remove a number from the blocked list
|
|
Future<void> unblockNumber(String number) async {
|
|
if (number.isEmpty) return;
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
List<String> blockedNumbers = prefs.getStringList('blockedNumbers') ?? [];
|
|
|
|
if (blockedNumbers.contains(number)) {
|
|
blockedNumbers.remove(number);
|
|
await prefs.setStringList('blockedNumbers', blockedNumbers);
|
|
print('$number has been unblocked');
|
|
} else {
|
|
print('$number is not blocked');
|
|
}
|
|
}
|
|
|
|
// Check if a number is blocked
|
|
Future<bool> isNumberBlocked(String number) async {
|
|
if (number.isEmpty) return false;
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
List<String> blockedNumbers = prefs.getStringList('blockedNumbers') ?? [];
|
|
return blockedNumbers.contains(number);
|
|
}
|
|
}
|