Reviewed-on: #16 Co-authored-by: Florian Griffon <florian.griffon@epitech.eu> Co-committed-by: Florian Griffon <florian.griffon@epitech.eu>
This commit is contained in:
parent
d8c9585f85
commit
518e49b3e6
@ -3,6 +3,8 @@
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.READ_BLOCKED_NUMBERS" />
|
||||
<uses-permission android:name="android.permission.WRITE_BLOCKED_NUMBERS" />
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
|
@ -3,6 +3,8 @@
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.READ_BLOCKED_NUMBERS" />
|
||||
<uses-permission android:name="android.permission.WRITE_BLOCKED_NUMBERS" />
|
||||
<application
|
||||
android:label="com.example.dialer"
|
||||
android:name="${applicationName}"
|
||||
|
@ -4,6 +4,8 @@
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.READ_BLOCKED_NUMBERS" />
|
||||
<uses-permission android:name="android.permission.WRITE_BLOCKED_NUMBERS" />
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
|
167
dialer/lib/features/settings/blocked/settings_blocked.dart
Normal file
167
dialer/lib/features/settings/blocked/settings_blocked.dart
Normal file
@ -0,0 +1,167 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class BlockedNumbersPage extends StatefulWidget {
|
||||
const BlockedNumbersPage({super.key});
|
||||
|
||||
@override
|
||||
_BlockedNumbersPageState createState() => _BlockedNumbersPageState();
|
||||
}
|
||||
|
||||
class _BlockedNumbersPageState extends State<BlockedNumbersPage> {
|
||||
bool _blockUnknownNumbers = false; // Toggle for blocking unknown numbers
|
||||
List<String> _blockedNumbers = []; // List of blocked numbers
|
||||
final TextEditingController _numberController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadPreferences(); // Load data on initialization
|
||||
}
|
||||
|
||||
// Load preferences from local storage
|
||||
Future<void> _loadPreferences() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
setState(() {
|
||||
_blockUnknownNumbers = prefs.getBool('blockUnknownNumbers') ?? false;
|
||||
_blockedNumbers = prefs.getStringList('blockedNumbers') ?? [];
|
||||
});
|
||||
}
|
||||
|
||||
// Save preferences to local storage
|
||||
Future<void> _savePreferences() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool('blockUnknownNumbers', _blockUnknownNumbers);
|
||||
await prefs.setStringList('blockedNumbers', _blockedNumbers);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
title: const Text('Blocked Numbers'),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
SwitchListTile(
|
||||
title: const Text(
|
||||
'Block Unknown Numbers',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
value: _blockUnknownNumbers,
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
_blockUnknownNumbers = value;
|
||||
_savePreferences(); // Save the state to local storage
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ListTile(
|
||||
title: const Text(
|
||||
'Blocked Numbers',
|
||||
style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: _blockedNumbers.isEmpty
|
||||
? const Text(
|
||||
'No blocked numbers',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
..._blockedNumbers.map(
|
||||
(number) => ListTile(
|
||||
title: Text(
|
||||
number,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete, color: Colors.red),
|
||||
onPressed: () => _unblockNumber(number),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(color: Colors.grey),
|
||||
ListTile(
|
||||
title: const Text(
|
||||
'Block a Number',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
trailing: const Icon(Icons.add, color: Colors.white),
|
||||
onTap: () => _showBlockNumberDialog(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Function to block a number
|
||||
void _blockNumber(String number) {
|
||||
if (number.isNotEmpty && !_blockedNumbers.contains(number)) {
|
||||
setState(() {
|
||||
_blockedNumbers.add(number);
|
||||
_savePreferences(); // Save the updated list
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('$number has been blocked')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to unblock a number
|
||||
void _unblockNumber(String number) {
|
||||
setState(() {
|
||||
_blockedNumbers.remove(number);
|
||||
_savePreferences(); // Save the updated list
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('$number has been unblocked')),
|
||||
);
|
||||
}
|
||||
|
||||
// Dialog for blocking a new number
|
||||
void _showBlockNumberDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
backgroundColor: Colors.grey[900],
|
||||
title: const Text('Block a Number', style: TextStyle(color: Colors.white)),
|
||||
content: TextField(
|
||||
controller: _numberController,
|
||||
keyboardType: TextInputType.phone,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Enter number',
|
||||
hintStyle: TextStyle(color: Colors.grey),
|
||||
),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Cancel', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_blockNumber(_numberController.text);
|
||||
_numberController.clear();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Block', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_numberController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:dialer/features/settings/call/settingsCall.dart';
|
||||
import 'package:dialer/features/settings/sim/settings_accounts.dart';
|
||||
import 'package:dialer/features/settings/key/manage_keys_page.dart';
|
||||
import 'package:dialer/features/settings/blocked/settings_blocked.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
const SettingsPage({super.key});
|
||||
@ -28,9 +29,15 @@ class SettingsPage extends StatelessWidget {
|
||||
MaterialPageRoute(builder: (context) => const KeyManagementPage()),
|
||||
);
|
||||
break;
|
||||
// Add more cases for other settings pages
|
||||
case 'Blocked numbers':
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const BlockedNumbersPage()),
|
||||
);
|
||||
break;
|
||||
// Add more cases for other settings pages
|
||||
default:
|
||||
// Handle default or unknown settings
|
||||
// Handle default or unknown settings
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -41,6 +48,7 @@ class SettingsPage extends StatelessWidget {
|
||||
'Calling settings',
|
||||
'Page of telephone accounts',
|
||||
'Key management',
|
||||
'Blocked numbers'
|
||||
];
|
||||
|
||||
return Scaffold(
|
||||
|
@ -35,6 +35,7 @@ dependencies:
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
url_launcher: ^6.1.9 # To manage system dialer. Call, message...
|
||||
shared_preferences: ^2.3.3 # Local storage (no critical data)
|
||||
cupertino_icons: ^1.0.8
|
||||
flutter_contacts: ^1.1.9+2
|
||||
permission_handler: ^11.3.1 # For handling permissions
|
||||
|
Loading…
Reference in New Issue
Block a user