From b9ea62f8c1a59e4c6b57942f7bac7d9b7911eae0 Mon Sep 17 00:00:00 2001 From: AlexisDanlos <91090088+AlexisDanlos@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:58:22 +0100 Subject: [PATCH] voicemail settings --- dialer/lib/features/settings/settings.dart | 16 +++ .../settings/voicemail/voicemail.dart | 132 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 dialer/lib/features/settings/voicemail/voicemail.dart diff --git a/dialer/lib/features/settings/settings.dart b/dialer/lib/features/settings/settings.dart index bdc22f3..ed5fe37 100644 --- a/dialer/lib/features/settings/settings.dart +++ b/dialer/lib/features/settings/settings.dart @@ -4,6 +4,8 @@ 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/sorting/sorting.dart'; +import 'package:dialer/features/settings/voicemail/voicemail.dart'; class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); @@ -28,6 +30,18 @@ class SettingsPage extends StatelessWidget { MaterialPageRoute(builder: (context) => const GestionDeClesPage()), ); break; + case 'Sorting settings': + Navigator.push( + context, + MaterialPageRoute(builder: (context) => const SortingSettingsPage()), + ); + break; + case 'Messagerie vocale': + Navigator.push( + context, + MaterialPageRoute(builder: (context) => Voicemail()), + ); + break; // Add more cases for other settings pages default: // Handle default or unknown settings @@ -41,6 +55,8 @@ class SettingsPage extends StatelessWidget { 'Calling settings', 'Page des comptes téléphoniques', 'Gestion de clés', // Add the new option here + 'Sorting settings', + 'Messagerie vocale', ]; return Scaffold( diff --git a/dialer/lib/features/settings/voicemail/voicemail.dart b/dialer/lib/features/settings/voicemail/voicemail.dart new file mode 100644 index 0000000..1441724 --- /dev/null +++ b/dialer/lib/features/settings/voicemail/voicemail.dart @@ -0,0 +1,132 @@ +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class Voicemail extends StatefulWidget { + @override + _VoicemailState createState() => _VoicemailState(); +} + +class _VoicemailState extends State { + final _formKey = GlobalKey(); + final TextEditingController _customController = TextEditingController(); + + String _selectedProvider = 'SFR'; + String _voicemailNumber = ''; + bool _isCustomNumber = false; + + // List of French internet providers and their voicemail numbers + final Map _providers = { + 'SFR': '123', + 'Orange': '888', + 'Bouygues': '660', + 'Free': '666', + 'Custom': '', + }; + + @override + void initState() { + super.initState(); + _loadVoicemailNumber(); + } + + void _loadVoicemailNumber() async { + final prefs = await SharedPreferences.getInstance(); + setState(() { + _voicemailNumber = prefs.getString('voicemailNumber') ?? ''; + _isCustomNumber = !_providers.containsValue(_voicemailNumber); + _selectedProvider = _isCustomNumber ? 'Custom' : _providers.keys.firstWhere((key) => _providers[key] == _voicemailNumber, orElse: () => 'SFR'); + _customController.text = _isCustomNumber ? _voicemailNumber : ''; + }); + } + + void _saveVoicemailNumber() async { + final prefs = await SharedPreferences.getInstance(); + prefs.setString('voicemailNumber', _voicemailNumber); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.black, + appBar: AppBar( + title: Text('Messagerie vocale'), + ), + body: Form( + key: _formKey, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + DropdownButtonFormField( + value: _selectedProvider, + decoration: InputDecoration( + labelText: 'Selectionnez un fournisseur', + border: OutlineInputBorder(), + ), + items: _providers.keys.map((String provider) { + return DropdownMenuItem( + value: provider, + child: Text(provider), + ); + }).toList(), + onChanged: (String? newValue) { + setState(() { + _selectedProvider = newValue!; + _isCustomNumber = _selectedProvider == 'Custom'; + _voicemailNumber = _isCustomNumber ? _customController.text : _providers[_selectedProvider]!; + }); + }, + ), + SizedBox(height: 20), + if (_isCustomNumber) + TextFormField( + controller: _customController, + keyboardType: TextInputType.phone, + decoration: InputDecoration( + labelText: 'Entrez un numéro de messagerie vocale', + border: OutlineInputBorder(), + ), + validator: (value) { + if (_isCustomNumber && value!.isEmpty) { + return 'Veuillez entrer un numéro de messagerie vocale'; + } + return null; + }, + onChanged: (value) { + _voicemailNumber = value; + }, + ), + SizedBox(height: 20), + const Spacer(), + ElevatedButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + _voicemailNumber = _isCustomNumber ? _customController.text : _providers[_selectedProvider]!; + _saveVoicemailNumber(); + Navigator.pop(context); + } + }, + child: Text('Enregistrer'), + ), + // Padding( + // // center the button + // padding: const Edge + // child: ElevatedButton( + // onPressed: () { + // if (_formKey.currentState!.validate()) { + // _voicemailNumber = _isCustomNumber ? _customController.text : _providers[_selectedProvider]!; + // _saveVoicemailNumber(); + // Navigator.pop(context); + // } + // }, + // child: Text('Save'), + // ), + // ), + ], + ), + ), + ), + ); + } +}