133 lines
4.6 KiB
Dart
133 lines
4.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class Voicemail extends StatefulWidget {
|
|
@override
|
|
_VoicemailState createState() => _VoicemailState();
|
|
}
|
|
|
|
class _VoicemailState extends State<Voicemail> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
final TextEditingController _customController = TextEditingController();
|
|
|
|
String _selectedProvider = 'SFR';
|
|
String _voicemailNumber = '';
|
|
bool _isCustomNumber = false;
|
|
|
|
// List of French internet providers and their voicemail numbers
|
|
final Map<String, String> _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: <Widget>[
|
|
DropdownButtonFormField<String>(
|
|
value: _selectedProvider,
|
|
decoration: InputDecoration(
|
|
labelText: 'Selectionnez un fournisseur',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
items: _providers.keys.map((String provider) {
|
|
return DropdownMenuItem<String>(
|
|
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'),
|
|
// ),
|
|
// ),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|