display settings in settings
This commit is contained in:
parent
50235b13c5
commit
4681c73959
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:dialer/features/settings/call/settingsCall.dart';
|
import 'package:dialer/features/settings/call/settingsCall.dart';
|
||||||
import 'package:dialer/features/settings/sim/settings_accounts.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/key/manage_keys_page.dart';
|
||||||
|
import 'package:dialer/features/settings/sorting/sorting.dart';
|
||||||
|
|
||||||
class SettingsPage extends StatelessWidget {
|
class SettingsPage extends StatelessWidget {
|
||||||
const SettingsPage({super.key});
|
const SettingsPage({super.key});
|
||||||
@ -28,6 +29,12 @@ class SettingsPage extends StatelessWidget {
|
|||||||
MaterialPageRoute(builder: (context) => const GestionDeClesPage()),
|
MaterialPageRoute(builder: (context) => const GestionDeClesPage()),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'Sorting settings':
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => const SortingSettingsPage()),
|
||||||
|
);
|
||||||
|
break;
|
||||||
// Add more cases for other settings pages
|
// Add more cases for other settings pages
|
||||||
default:
|
default:
|
||||||
// Handle default or unknown settings
|
// Handle default or unknown settings
|
||||||
@ -41,6 +48,7 @@ class SettingsPage extends StatelessWidget {
|
|||||||
'Calling settings',
|
'Calling settings',
|
||||||
'Page des comptes téléphoniques',
|
'Page des comptes téléphoniques',
|
||||||
'Gestion de clés', // Add the new option here
|
'Gestion de clés', // Add the new option here
|
||||||
|
'Sorting settings',
|
||||||
];
|
];
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
153
dialer/lib/features/settings/sorting/sorting.dart
Normal file
153
dialer/lib/features/settings/sorting/sorting.dart
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
// store in shared preferences the sorting order of contacts
|
||||||
|
|
||||||
|
class SortingSettings {
|
||||||
|
static const _key = 'sorting_order';
|
||||||
|
|
||||||
|
static Future<void> setSortingOrder(SortingOrder order) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_key, order.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<SortingOrder> getSortingOrder() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final index = prefs.getInt(_key) ?? SortingOrder.ascending.index;
|
||||||
|
return SortingOrder.values[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
static const _displayKey = 'contact_display';
|
||||||
|
|
||||||
|
static Future<void> setContactDisplay(ContactDisplay display) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_displayKey, display.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<ContactDisplay> getContactDisplay() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final index = prefs.getInt(_displayKey) ?? ContactDisplay.nameFirst.index;
|
||||||
|
return ContactDisplay.values[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SortingOrder { ascending, descending }
|
||||||
|
enum ContactDisplay { nameFirst, firstNameFirst }
|
||||||
|
|
||||||
|
class SortingSettingsPage extends StatefulWidget {
|
||||||
|
const SortingSettingsPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SortingSettingsPageState createState() => _SortingSettingsPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SortingSettingsPageState extends State<SortingSettingsPage> {
|
||||||
|
SortingOrder _sortingOrder = SortingOrder.ascending;
|
||||||
|
ContactDisplay _contactDisplay = ContactDisplay.nameFirst;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_fetchSortingOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _fetchSortingOrder() async {
|
||||||
|
final order = await SortingSettings.getSortingOrder();
|
||||||
|
final display = await SortingSettings.getContactDisplay();
|
||||||
|
setState(() {
|
||||||
|
_sortingOrder = order;
|
||||||
|
_contactDisplay = display;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onOrderSelected(SortingOrder? order) {
|
||||||
|
setState(() {
|
||||||
|
_sortingOrder = order!;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onDisplaySelected(ContactDisplay? display) {
|
||||||
|
setState(() {
|
||||||
|
_contactDisplay = display!;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _saveSortingOrder() async {
|
||||||
|
await SortingSettings.setSortingOrder(_sortingOrder);
|
||||||
|
await SortingSettings.setContactDisplay(_contactDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Affichage'),
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
// subtitle for the sorting order
|
||||||
|
const ListTile(
|
||||||
|
title: Text(
|
||||||
|
'Ordre de tri',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: const Text('Croissant'),
|
||||||
|
leading: Radio<SortingOrder>(
|
||||||
|
value: SortingOrder.ascending,
|
||||||
|
groupValue: _sortingOrder,
|
||||||
|
onChanged: (SortingOrder? order) => _onOrderSelected(order),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: const Text('Décroissant'),
|
||||||
|
leading: Radio<SortingOrder>(
|
||||||
|
value: SortingOrder.descending,
|
||||||
|
groupValue: _sortingOrder,
|
||||||
|
onChanged: (SortingOrder? order) => _onOrderSelected(order),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
// subtitle for the contact display
|
||||||
|
const ListTile(
|
||||||
|
title: Text(
|
||||||
|
'Affichage des contacts',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: const Text('Exemple 1'),
|
||||||
|
leading: Radio<ContactDisplay>(
|
||||||
|
value: ContactDisplay.nameFirst,
|
||||||
|
groupValue: _contactDisplay,
|
||||||
|
onChanged: (ContactDisplay? display) => _onDisplaySelected(display),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: const Text('Exemple 2'),
|
||||||
|
leading: Radio<ContactDisplay>(
|
||||||
|
value: ContactDisplay.firstNameFirst,
|
||||||
|
groupValue: _contactDisplay,
|
||||||
|
onChanged: (ContactDisplay? order) => _onDisplaySelected(order),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: ElevatedButton(
|
||||||
|
// call _saveSortingOrder then go back to previous screen
|
||||||
|
onPressed: () {
|
||||||
|
_saveSortingOrder();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Enregistrer'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -44,6 +44,7 @@ dependencies:
|
|||||||
file_picker: ^5.2.5
|
file_picker: ^5.2.5
|
||||||
asn1lib: ^1.0.0
|
asn1lib: ^1.0.0
|
||||||
intl_utils: ^2.0.7
|
intl_utils: ^2.0.7
|
||||||
|
shared_preferences: ^2.3.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user