204 lines
7.4 KiB
Dart
204 lines
7.4 KiB
Dart
// import 'package:flutter/material.dart';
|
|
// import 'package:flutter_contacts/flutter_contacts.dart';
|
|
// import '../../../widgets/color_darkener.dart';
|
|
// import '../contacts/contact_state.dart';
|
|
// import '../contacts/widgets/add_contact_button.dart';
|
|
// import '../contacts/widgets/contact_modal.dart';
|
|
// import '../contacts/widgets/share_own_qr.dart';
|
|
// import 'package:dialer/widgets/username_color_generator.dart';
|
|
|
|
// class FavoritePage extends StatefulWidget {
|
|
// final List<Contact> contacts;
|
|
// final double scrollOffset;
|
|
|
|
// const FavoritePage({
|
|
// super.key,
|
|
// required this.contacts,
|
|
// required this.scrollOffset,
|
|
// });
|
|
|
|
// @override
|
|
// _FavoritePageState createState() => _FavoritePageState();
|
|
// }
|
|
|
|
// class _FavoritePageState extends State<FavoritePage> {
|
|
// late ScrollController _scrollController;
|
|
// List<Contact> _favoriteContacts = []; // Local list of favorite contacts
|
|
|
|
// @override
|
|
// void initState() {
|
|
// super.initState();
|
|
// _favoriteContacts = widget.contacts.where((contact) => contact.isStarred).toList(); // Filter only favorites
|
|
// _scrollController = ScrollController(initialScrollOffset: widget.scrollOffset);
|
|
// _scrollController.addListener(_onScroll);
|
|
// }
|
|
|
|
// void _onScroll() {
|
|
// final contactState = ContactState.of(context);
|
|
// contactState.setScrollOffset(_scrollController.offset);
|
|
// }
|
|
|
|
// Future<void> _refreshContacts() async {
|
|
// if (await FlutterContacts.requestPermission()) {
|
|
// final updatedContacts = await FlutterContacts.getContacts(
|
|
// withProperties: true,
|
|
// withThumbnail: true,
|
|
// );
|
|
// setState(() {
|
|
// _favoriteContacts = updatedContacts.where((contact) => contact.isStarred).toList();
|
|
// });
|
|
// }
|
|
// }
|
|
|
|
// void _toggleFavorite(Contact contact) async {
|
|
// if (await FlutterContacts.requestPermission()) {
|
|
// try {
|
|
// // Fetch all contacts (this can be slow if there are many contacts)
|
|
// List<Contact> allContacts = await FlutterContacts.getContacts(
|
|
// withProperties: true,
|
|
// withThumbnail: true,
|
|
// withAccounts: true,
|
|
// );
|
|
|
|
// // Find the specific contact by matching contact.id
|
|
// Contact? contactToUpdate = allContacts.firstWhere(
|
|
// (c) => c.id == contact.id,
|
|
// orElse: () => throw Exception("Contact not found"),
|
|
// );
|
|
|
|
// if (contactToUpdate != null) {
|
|
// contactToUpdate.isStarred = !contactToUpdate.isStarred;
|
|
|
|
// // Update the contact
|
|
// await FlutterContacts.updateContact(contactToUpdate);
|
|
|
|
// // Refresh the favorite contacts list
|
|
// setState(() {
|
|
// _favoriteContacts = allContacts.where((c) => c.isStarred).toList();
|
|
// });
|
|
// }
|
|
// } catch (e) {
|
|
// print("Error updating favorite status: $e");
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// return Scaffold(
|
|
// backgroundColor: Colors.black,
|
|
// appBar: AppBar(
|
|
// title: const Text('Favorites'),
|
|
// backgroundColor: Colors.black,
|
|
// actions: [
|
|
// IconButton(
|
|
// icon: const Icon(Icons.refresh),
|
|
// onPressed: _refreshContacts,
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// body: _favoriteContacts.isEmpty
|
|
// ? Center(
|
|
// child: Text(
|
|
// 'No favorite contacts yet!',
|
|
// style: TextStyle(color: Colors.white),
|
|
// ),
|
|
// )
|
|
// : ListView.builder(
|
|
// controller: _scrollController,
|
|
// itemCount: _favoriteContacts.length,
|
|
// itemBuilder: (context, index) {
|
|
// Contact contact = _favoriteContacts[index];
|
|
// String phoneNumber = contact.phones.isNotEmpty
|
|
// ? contact.phones.first.number
|
|
// : 'No phone number';
|
|
// Color avatarColor = generateColorFromName(contact.displayName);
|
|
|
|
// return ListTile(
|
|
// leading: (contact.thumbnail != null && contact.thumbnail!.isNotEmpty)
|
|
// ? CircleAvatar(
|
|
// backgroundImage: MemoryImage(contact.thumbnail!),
|
|
// )
|
|
// : CircleAvatar(
|
|
// backgroundColor: avatarColor,
|
|
// child: Text(
|
|
// contact.displayName.isNotEmpty
|
|
// ? contact.displayName[0].toUpperCase()
|
|
// : '?',
|
|
// style: TextStyle(color: darken(avatarColor, 0.4)),
|
|
// ),
|
|
// ),
|
|
// title: Text(contact.displayName, style: TextStyle(color: Colors.white)),
|
|
// subtitle: Text(phoneNumber, style: TextStyle(color: Colors.white70)),
|
|
// onTap: () {
|
|
// showModalBottomSheet(
|
|
// context: context,
|
|
// isScrollControlled: true,
|
|
// backgroundColor: Colors.transparent,
|
|
// builder: (context) {
|
|
// return ContactModal(
|
|
// contact: contact,
|
|
// onEdit: () async {
|
|
// // Trigger edit logic and refresh contacts
|
|
// if (await FlutterContacts.requestPermission()) {
|
|
// final updatedContact =
|
|
// await FlutterContacts.openExternalEdit(contact.id);
|
|
// if (updatedContact != null) {
|
|
// await _refreshContacts();
|
|
// Navigator.of(context).pop();
|
|
// ScaffoldMessenger.of(context).showSnackBar(
|
|
// SnackBar(content: Text('${contact.displayName} updated successfully!')),
|
|
// );
|
|
// } else {
|
|
// ScaffoldMessenger.of(context).showSnackBar(
|
|
// SnackBar(content: Text('Edit canceled or failed.')),
|
|
// );
|
|
// }
|
|
// }
|
|
// },
|
|
// onToggleFavorite: () {
|
|
// _toggleFavorite(contact);
|
|
// },
|
|
// isFavorite: contact.isStarred,
|
|
// );
|
|
// },
|
|
// );
|
|
// },
|
|
// );
|
|
// },
|
|
// ),
|
|
// );
|
|
// }
|
|
|
|
// @override
|
|
// void dispose() {
|
|
// _scrollController.dispose();
|
|
// super.dispose();
|
|
// }
|
|
// }
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class FavoritePage extends StatefulWidget {
|
|
const FavoritePage({super.key});
|
|
|
|
@override
|
|
_FavoritePageState createState() => _FavoritePageState();
|
|
}
|
|
|
|
class _FavoritePageState extends State<FavoritePage> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
body: Center( // Center the text within the body
|
|
child: Text(
|
|
"Hello",
|
|
style: TextStyle(color: Colors.white), // Change text color for visibility
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|