Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
a8e64ff169 | |||
|
3a4a3816a8 | ||
|
cb060ba77b |
@ -12,4 +12,9 @@ class ContactService {
|
|||||||
Future<void> addNewContact(Contact contact) async {
|
Future<void> addNewContact(Contact contact) async {
|
||||||
await FlutterContacts.insertContact(contact);
|
await FlutterContacts.insertContact(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> toogleFavorite(Contact contact) async {
|
||||||
|
contact.isStarred = !contact.isStarred;
|
||||||
|
await FlutterContacts.updateContact(contact);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,21 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
// import 'dart:developer';
|
||||||
|
import 'package:dialer/features/favorites/favorites_state.dart';
|
||||||
|
|
||||||
|
|
||||||
class FavoritePage extends StatefulWidget {
|
class FavoritePage extends StatefulWidget {
|
||||||
const FavoritePage({super.key});
|
const FavoritePage({super.key});
|
||||||
|
|
||||||
@override
|
@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")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
46
dialer/lib/features/favorites/favorites_state.dart
Normal file
46
dialer/lib/features/favorites/favorites_state.dart
Normal 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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -38,6 +38,7 @@ dependencies:
|
|||||||
flutter_contacts: ^1.1.9+2
|
flutter_contacts: ^1.1.9+2
|
||||||
permission_handler: ^10.2.0 # For handling permissions
|
permission_handler: ^10.2.0 # For handling permissions
|
||||||
cached_network_image: ^3.2.3 # For caching contact images
|
cached_network_image: ^3.2.3 # For caching contact images
|
||||||
|
shared_preferences: ^2.3.2 # For storing user preferences
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user