Compare commits

..

No commits in common. "6ffd179f207b7999ef467932dfd560f45285551f" and "e6807b865b98a6481443294c23cabf0b44cccb59" have entirely different histories.

7 changed files with 102 additions and 81 deletions

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import '../../widgets/contact_service.dart'; import '../../widgets/contact_service.dart';
import '../../widgets/contact_service.dart';
class CompositionPage extends StatefulWidget { class CompositionPage extends StatefulWidget {
const CompositionPage({super.key}); const CompositionPage({super.key});
@ -14,6 +15,7 @@ class _CompositionPageState extends State<CompositionPage> {
List<Contact> _allContacts = []; List<Contact> _allContacts = [];
List<Contact> _filteredContacts = []; List<Contact> _filteredContacts = [];
final ContactService _contactService = ContactService(); final ContactService _contactService = ContactService();
final ContactService _contactService = ContactService();
@override @override
void initState() { void initState() {
@ -81,9 +83,9 @@ class _CompositionPageState extends State<CompositionPage> {
// Top half: Display contacts matching dialed number // Top half: Display contacts matching dialed number
Expanded( Expanded(
flex: 2, flex: 2,
child: child: Container(
Container( padding: const EdgeInsets.only(
padding: const EdgeInsets.only(top: 42.0, left: 16.0, right: 16.0, bottom: 16.0), top: 42.0, left: 16.0, right: 16.0, bottom: 16.0),
color: Colors.black, color: Colors.black,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -95,12 +97,14 @@ class _CompositionPageState extends State<CompositionPage> {
return ListTile( return ListTile(
title: Text( title: Text(
contact.displayName, contact.displayName,
style: const TextStyle(color: Colors.white), style:
const TextStyle(color: Colors.white),
), ),
subtitle: contact.phones.isNotEmpty subtitle: contact.phones.isNotEmpty
? Text( ? Text(
contact.phones.first.number, contact.phones.first.number,
style: const TextStyle(color: Colors.grey), style: const TextStyle(
color: Colors.grey),
) )
: null, : null,
trailing: Row( trailing: Row(
@ -108,16 +112,22 @@ class _CompositionPageState extends State<CompositionPage> {
children: [ children: [
// Call button // Call button
IconButton( IconButton(
icon: Icon(Icons.phone, color: Colors.green[300], size: 20), icon: Icon(Icons.phone,
color: Colors.green[300],
size: 20),
onPressed: () { onPressed: () {
print('Calling ${contact.displayName}'); print(
'Calling ${contact.displayName}');
}, },
), ),
// Text button // Text button
IconButton( IconButton(
icon: Icon(Icons.message, color: Colors.blue[300], size: 20), icon: Icon(Icons.message,
color: Colors.blue[300],
size: 20),
onPressed: () { onPressed: () {
print('Texting ${contact.displayName}'); print(
'Texting ${contact.displayName}');
}, },
), ),
], ],
@ -127,7 +137,12 @@ class _CompositionPageState extends State<CompositionPage> {
}, },
); );
}).toList() }).toList()
: [Center(child: Text('No contacts found', style: TextStyle(color: Colors.white)))], : [
Center(
child: Text('No contacts found',
style:
TextStyle(color: Colors.white)))
],
), ),
), ),
], ],
@ -152,14 +167,16 @@ class _CompositionPageState extends State<CompositionPage> {
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
dialedNumber, dialedNumber,
style: const TextStyle(fontSize: 24, color: Colors.white), style: const TextStyle(
fontSize: 24, color: Colors.white),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
), ),
IconButton( IconButton(
onPressed: _onClearPress, onPressed: _onClearPress,
icon: const Icon(Icons.backspace, color: Colors.white), icon: const Icon(Icons.backspace,
color: Colors.white),
), ),
], ],
), ),
@ -172,7 +189,8 @@ class _CompositionPageState extends State<CompositionPage> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('1'), _buildDialButton('1'),
_buildDialButton('2'), _buildDialButton('2'),
@ -180,7 +198,8 @@ class _CompositionPageState extends State<CompositionPage> {
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('4'), _buildDialButton('4'),
_buildDialButton('5'), _buildDialButton('5'),
@ -188,7 +207,8 @@ class _CompositionPageState extends State<CompositionPage> {
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('7'), _buildDialButton('7'),
_buildDialButton('8'), _buildDialButton('8'),
@ -196,7 +216,8 @@ class _CompositionPageState extends State<CompositionPage> {
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('*'), _buildDialButton('*'),
_buildDialButton('0'), _buildDialButton('0'),

View File

@ -17,10 +17,8 @@ class _ContactPageState extends State<ContactPage> {
return Scaffold( return Scaffold(
body: contactState.loading body: contactState.loading
? const LoadingIndicatorWidget() ? const LoadingIndicatorWidget()
: AlphabetScrollPage( // : ContactListWidget(contacts: contactState.contacts),
scrollOffset: contactState.scrollOffset, : AlphabetScrollPage(scrollOffset: contactState.scrollOffset),
contacts: contactState.contacts, // Use all contacts here
),
); );
} }
} }

View File

@ -19,15 +19,12 @@ class ContactState extends StatefulWidget {
class _ContactStateState extends State<ContactState> { class _ContactStateState extends State<ContactState> {
final ContactService _contactService = ContactService(); final ContactService _contactService = ContactService();
List<Contact> _allContacts = []; List<Contact> _contacts = [];
List<Contact> _favoriteContacts = [];
bool _loading = true; bool _loading = true;
double _scrollOffset = 0.0; double _scrollOffset = 0.0;
Contact? _selfContact = Contact(); Contact? _selfContact = Contact();
// Getters for all contacts and favorites List<Contact> get contacts => _contacts;
List<Contact> get contacts => _allContacts;
List<Contact> get favoriteContacts => _favoriteContacts;
bool get loading => _loading; bool get loading => _loading;
double get scrollOffset => _scrollOffset; double get scrollOffset => _scrollOffset;
Contact? get selfContact => _selfContact; Contact? get selfContact => _selfContact;
@ -35,7 +32,9 @@ class _ContactStateState extends State<ContactState> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
fetchContacts(); // Fetch all contacts by default fetchContacts();
// Add listener for contact changes
FlutterContacts.addListener(_onContactChange); FlutterContacts.addListener(_onContactChange);
} }
@ -43,33 +42,20 @@ class _ContactStateState extends State<ContactState> {
@override @override
void dispose() { void dispose() {
// Remove listener
FlutterContacts.removeListener(_onContactChange); FlutterContacts.removeListener(_onContactChange);
super.dispose(); super.dispose();
} }
// Fetch all contacts Future<void> fetchContacts({bool onlyStarred = false}) async {
Future<void> fetchContacts() async { List<Contact> contacts = onlyStarred
setState(() => _loading = true); ? await _contactService.fetchFavoriteContacts()
try { : await _contactService.fetchContacts();
List<Contact> contacts = await _contactService.fetchContacts();
_processContacts(contacts);
} finally {
setState(() => _loading = false);
}
}
// Fetch only favorite contacts debugPrint(
Future<void> fetchFavoriteContacts() async { "Fetched ${contacts.length} ${onlyStarred ? 'favorite' : ''} contacts");
setState(() => _loading = true);
try {
List<Contact> contacts = await _contactService.fetchFavoriteContacts();
setState(() => _favoriteContacts = contacts);
} finally {
setState(() => _loading = false);
}
}
void _processContacts(List<Contact> contacts) { // Find selfContact before filtering
_selfContact = contacts.firstWhere( _selfContact = contacts.firstWhere(
(contact) => contact.displayName.toLowerCase() == "user", (contact) => contact.displayName.toLowerCase() == "user",
orElse: () => Contact(), orElse: () => Contact(),
@ -84,9 +70,8 @@ class _ContactStateState extends State<ContactState> {
contacts.sort((a, b) => a.displayName.compareTo(b.displayName)); contacts.sort((a, b) => a.displayName.compareTo(b.displayName));
setState(() { setState(() {
_allContacts = contacts; _contacts = contacts;
_favoriteContacts = _loading = false;
contacts.where((contact) => contact.isStarred).toList();
_selfContact = _selfContact; _selfContact = _selfContact;
}); });
} }
@ -111,7 +96,6 @@ class _ContactStateState extends State<ContactState> {
} }
} }
class _InheritedContactState extends InheritedWidget { class _InheritedContactState extends InheritedWidget {
final _ContactStateState data; final _ContactStateState data;

View File

@ -2,20 +2,17 @@ import 'package:dialer/widgets/username_color_generator.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import '../contact_state.dart'; import '../contact_state.dart';
import '../contact_state.dart';
import '../../../widgets/color_darkener.dart'; import '../../../widgets/color_darkener.dart';
import 'add_contact_button.dart'; import 'add_contact_button.dart';
import 'contact_modal.dart'; import 'contact_modal.dart';
import 'contact_modal.dart';
import 'share_own_qr.dart'; import 'share_own_qr.dart';
class AlphabetScrollPage extends StatefulWidget { class AlphabetScrollPage extends StatefulWidget {
final double scrollOffset; final double scrollOffset;
final List<Contact> contacts;
const AlphabetScrollPage({ const AlphabetScrollPage({super.key, required this.scrollOffset});
super.key,
required this.scrollOffset,
required this.contacts,
});
@override @override
_AlphabetScrollPageState createState() => _AlphabetScrollPageState(); _AlphabetScrollPageState createState() => _AlphabetScrollPageState();
@ -27,7 +24,8 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_scrollController = ScrollController(initialScrollOffset: widget.scrollOffset); _scrollController =
ScrollController(initialScrollOffset: widget.scrollOffset);
_scrollController.addListener(_onScroll); _scrollController.addListener(_onScroll);
} }
@ -75,8 +73,13 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final contacts = widget.contacts; final contactState = ContactState.of(context);
final selfContact = ContactState.of(context).selfContact; final contacts = contactState.contacts;
final selfContact = contactState.selfContact;
final contactState = ContactState.of(context);
final contacts = contactState.contacts;
final selfContact = contactState.selfContact;
Map<String, List<Contact>> alphabetizedContacts = {}; Map<String, List<Contact>> alphabetizedContacts = {};
for (var contact in contacts) { for (var contact in contacts) {
@ -94,6 +97,8 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
return Scaffold( return Scaffold(
backgroundColor: Colors.black, backgroundColor: Colors.black,
body: Column( body: Column(
children: [
// Top buttons row
children: [ children: [
// Top buttons row // Top buttons row
Container( Container(
@ -115,11 +120,14 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
String letter = alphabetKeys[index]; String letter = alphabetKeys[index];
List<Contact> contactsForLetter = alphabetizedContacts[letter]!; List<Contact> contactsForLetter = alphabetizedContacts[letter]!;
List<Contact> contactsForLetter = alphabetizedContacts[letter]!;
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Alphabet Letter Header // Alphabet Letter Header
Padding( Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 16.0),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 16.0), vertical: 8.0, horizontal: 16.0),
child: Text( child: Text(
@ -139,12 +147,17 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
Color avatarColor = Color avatarColor =
generateColorFromName(contact.displayName); generateColorFromName(contact.displayName);
return ListTile( return ListTile(
leading: (contact.thumbnail != null &&
contact.thumbnail!.isNotEmpty)
leading: (contact.thumbnail != null && leading: (contact.thumbnail != null &&
contact.thumbnail!.isNotEmpty) contact.thumbnail!.isNotEmpty)
? CircleAvatar( ? CircleAvatar(
backgroundImage: backgroundImage:
MemoryImage(contact.thumbnail!), MemoryImage(contact.thumbnail!),
) )
backgroundImage:
MemoryImage(contact.thumbnail!),
)
: CircleAvatar( : CircleAvatar(
backgroundColor: avatarColor, backgroundColor: avatarColor,
child: Text( child: Text(
@ -157,6 +170,19 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
), ),
title: Text(contact.displayName, title: Text(contact.displayName,
style: TextStyle(color: Colors.white)), style: TextStyle(color: Colors.white)),
subtitle: Text(phoneNumber,
style: TextStyle(color: Colors.white70)),
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, subtitle: Text(phoneNumber,
style: TextStyle(color: Colors.white70)), style: TextStyle(color: Colors.white70)),
onTap: () { onTap: () {

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:dialer/widgets/username_color_generator.dart'; import 'package:dialer/widgets/username_color_generator.dart';
import 'package:flutter/material.dart';
class ContactModal extends StatelessWidget { class ContactModal extends StatelessWidget {
final Contact contact; final Contact contact;

View File

@ -1,31 +1,22 @@
import 'package:dialer/features/contacts/contact_state.dart';
import 'package:dialer/features/contacts/widgets/alphabet_scroll_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:dialer/widgets/loading_indicator.dart';
class FavoritesPage extends StatefulWidget { class FavoritePage extends StatefulWidget {
const FavoritesPage({super.key}); const FavoritePage({super.key});
@override @override
_FavoritesPageState createState() => _FavoritesPageState(); _FavoritePageState createState() => _FavoritePageState();
}
class _FavoritesPageState extends State<FavoritesPage> {
@override
void initState() {
super.initState();
} }
class _FavoritePageState extends State<FavoritePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final contactState = ContactState.of(context);
return Scaffold( return Scaffold(
body: contactState.loading backgroundColor: Colors.black,
? const LoadingIndicatorWidget() body: Center( // Center the text within the body
: AlphabetScrollPage( child: Text(
scrollOffset: contactState.scrollOffset, "Hello",
contacts: style: TextStyle(color: Colors.white), // Change text color for visibility
contactState.favoriteContacts, // Use only favorites here ),
), ),
); );
} }

View File

@ -140,7 +140,7 @@ class _MyHomePageState extends State<MyHomePage>
TabBarView( TabBarView(
controller: _tabController, controller: _tabController,
children: const [ children: const [
FavoritesPage(), FavoritePage(),
HistoryPage(), HistoryPage(),
ContactPage(), ContactPage(),
SettingsPage(), // Add your SettingsPage here SettingsPage(), // Add your SettingsPage here