Compare commits

...

3 Commits
dev ... alex

Author SHA1 Message Date
a8e64ff169 Add toggle favorite functionality and simplify favorite contact filtering 2024-11-06 16:27:38 +01:00
AlexisDanlos
3a4a3816a8 Update gradle.properties 2024-11-06 11:01:44 +01:00
AlexisDanlos
cb060ba77b Favorite page 2024-10-28 19:14:02 +01:00
4 changed files with 56 additions and 13 deletions

View File

@ -12,4 +12,9 @@ class ContactService {
Future<void> addNewContact(Contact contact) async {
await FlutterContacts.insertContact(contact);
}
Future<void> toogleFavorite(Contact contact) async {
contact.isStarred = !contact.isStarred;
await FlutterContacts.updateContact(contact);
}
}

View File

@ -1,21 +1,12 @@
import 'package:flutter/material.dart';
// import 'dart:developer';
import 'package:dialer/features/favorites/favorites_state.dart';
class FavoritePage extends StatefulWidget {
const FavoritePage({super.key});
@override
_FavoritePageState createState() => _FavoritePageState();
FavoriteContactListState createState() => FavoriteContactListState();
}
class _FavoritePageState extends State<FavoritePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
title: const Text('Favorites'),
),
body: Text("Hello")
);
}
}

View File

@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:dialer/features/contacts/contact_service.dart';
import 'package:dialer/widgets/loading_indicator.dart';
import 'package:dialer/features/contacts/widgets/alphabet_scroll_page.dart';
import 'package:dialer/features/favorites/favorites_page.dart';
class FavoriteContactListState extends State<FavoritePage> {
List<Contact> _contacts = [];
bool _loading = true;
final ContactService _contactService = ContactService();
bool get loading => _loading;
@override
void initState() {
super.initState();
_fetchContacts();
}
Future<void> _fetchContacts() async {
List<Contact> contacts = await _contactService.fetchContacts();
contacts = contacts.where((contact) => contact.phones.isNotEmpty).toList();
contacts.sort((a, b) => a.displayName.compareTo(b.displayName));
contacts = contacts.where((contact) => contact.isStarred).toList();
setState(() {
_contacts = contacts;
_loading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Contacts Favoris'),
),
body: _loading
? const LoadingIndicatorWidget()
: AlphabetScrollPage(
contacts: _contacts,
scrollOffset: 0.0,
),
);
}
}

View File

@ -38,6 +38,7 @@ dependencies:
flutter_contacts: ^1.1.9+2
permission_handler: ^10.2.0 # For handling permissions
cached_network_image: ^3.2.3 # For caching contact images
shared_preferences: ^2.3.2 # For storing user preferences
dev_dependencies:
flutter_test: