Compare commits
3 Commits
rework-app
...
dev
Author | SHA1 | Date | |
---|---|---|---|
b9dd156eca | |||
58ccd3a24c | |||
608218175a |
@ -4,7 +4,6 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../services/contact_service.dart';
|
||||
import '../../services/obfuscate_service.dart';
|
||||
import '../../services/call_service.dart';
|
||||
import '../contacts/widgets/add_contact_button.dart';
|
||||
|
||||
class CompositionPage extends StatefulWidget {
|
||||
const CompositionPage({super.key});
|
||||
@ -18,11 +17,7 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
List<Contact> _allContacts = [];
|
||||
List<Contact> _filteredContacts = [];
|
||||
final ContactService _contactService = ContactService();
|
||||
|
||||
// Instantiate the ObfuscateService
|
||||
final ObfuscateService _obfuscateService = ObfuscateService();
|
||||
|
||||
// Instantiate the CallService
|
||||
final CallService _callService = CallService();
|
||||
|
||||
@override
|
||||
@ -40,8 +35,13 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
void _filterContacts() {
|
||||
setState(() {
|
||||
_filteredContacts = _allContacts.where((contact) {
|
||||
final phoneMatch = contact.phones.any((phone) =>
|
||||
phone.number.replaceAll(RegExp(r'\D'), '').contains(dialedNumber));
|
||||
bool phoneMatch = contact.phones.any((phone) {
|
||||
final rawPhoneNumber = phone.number;
|
||||
final strippedPhoneNumber = rawPhoneNumber.replaceAll(RegExp(r'\D'), '');
|
||||
final strippedDialedNumber = dialedNumber.replaceAll(RegExp(r'\D'), '');
|
||||
return rawPhoneNumber.contains(dialedNumber) ||
|
||||
strippedPhoneNumber.contains(strippedDialedNumber);
|
||||
});
|
||||
final nameMatch = contact.displayName
|
||||
.toLowerCase()
|
||||
.contains(dialedNumber.toLowerCase());
|
||||
@ -57,6 +57,13 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
});
|
||||
}
|
||||
|
||||
void _onPlusPress() {
|
||||
setState(() {
|
||||
dialedNumber += '+';
|
||||
_filterContacts();
|
||||
});
|
||||
}
|
||||
|
||||
void _onDeletePress() {
|
||||
setState(() {
|
||||
if (dialedNumber.isNotEmpty) {
|
||||
@ -73,7 +80,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
});
|
||||
}
|
||||
|
||||
// Function to call a contact's number using the CallService
|
||||
void _makeCall(String phoneNumber) async {
|
||||
try {
|
||||
await _callService.makeGsmCall(context, phoneNumber: phoneNumber);
|
||||
@ -82,10 +88,12 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
});
|
||||
} catch (e) {
|
||||
debugPrint("Error making call: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to make call: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to send an SMS to a contact's number
|
||||
void _launchSms(String phoneNumber) async {
|
||||
final uri = Uri(scheme: 'sms', path: phoneNumber);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
@ -95,6 +103,20 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
}
|
||||
}
|
||||
|
||||
void _addContact() async {
|
||||
if (await FlutterContacts.requestPermission()) {
|
||||
final newContact = Contact()
|
||||
..phones = [Phone(dialedNumber.isNotEmpty ? dialedNumber : '')];
|
||||
final updatedContact = await FlutterContacts.openExternalInsert(newContact);
|
||||
if (updatedContact != null) {
|
||||
_fetchContacts();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Contact added successfully!')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -103,7 +125,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
// Top half: Display contacts matching dialed number
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Container(
|
||||
@ -115,57 +136,51 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: _filteredContacts.isNotEmpty
|
||||
? _filteredContacts.map((contact) {
|
||||
final phoneNumber = contact.phones.isNotEmpty
|
||||
? contact.phones.first.number
|
||||
: 'No phone number';
|
||||
return ListTile(
|
||||
title: Text(
|
||||
_obfuscateService.obfuscateData(contact.displayName),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
children: [
|
||||
..._filteredContacts.map((contact) {
|
||||
final phoneNumber = contact.phones.isNotEmpty
|
||||
? contact.phones.first.number
|
||||
: 'No phone number';
|
||||
return ListTile(
|
||||
title: Text(
|
||||
_obfuscateService.obfuscateData(contact.displayName),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
_obfuscateService.obfuscateData(phoneNumber),
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.phone, color: Colors.green[300], size: 20),
|
||||
onPressed: () => _makeCall(phoneNumber),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.message, color: Colors.blue[300], size: 20),
|
||||
onPressed: () => _launchSms(phoneNumber),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {},
|
||||
);
|
||||
}).toList(),
|
||||
ListTile(
|
||||
title: const Text(
|
||||
'Add a contact',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
_obfuscateService.obfuscateData(phoneNumber),
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Call button (Now using CallService)
|
||||
IconButton(
|
||||
icon: Icon(Icons.phone,
|
||||
color: Colors.green[300],
|
||||
size: 20),
|
||||
onPressed: () {
|
||||
_makeCall(phoneNumber); // Make a call using CallService
|
||||
},
|
||||
),
|
||||
// Message button
|
||||
IconButton(
|
||||
icon: Icon(Icons.message,
|
||||
color: Colors.blue[300],
|
||||
size: 20),
|
||||
onPressed: () {
|
||||
_launchSms(phoneNumber);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
// Handle contact selection if needed
|
||||
},
|
||||
);
|
||||
}).toList()
|
||||
: [],
|
||||
trailing: Icon(Icons.add, color: Colors.grey[600]),
|
||||
onTap: _addContact,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Bottom half: Dialpad and Dialed number display with erase button
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Container(
|
||||
@ -173,7 +188,6 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
// Display dialed number with erase button
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@ -182,61 +196,57 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
dialedNumber,
|
||||
style: const TextStyle(
|
||||
fontSize: 24, color: Colors.white),
|
||||
style: const TextStyle(fontSize: 24, color: Colors.white),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: _onClearPress,
|
||||
icon: const Icon(Icons.backspace,
|
||||
color: Colors.white),
|
||||
GestureDetector(
|
||||
onTap: _onDeletePress,
|
||||
onLongPress: _onClearPress,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Icon(Icons.backspace, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// Dialpad
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildDialButton('1'),
|
||||
_buildDialButton('2'),
|
||||
_buildDialButton('3'),
|
||||
_buildDialButton('1', Colors.white),
|
||||
_buildDialButton('2', Colors.white),
|
||||
_buildDialButton('3', Colors.white),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildDialButton('4'),
|
||||
_buildDialButton('5'),
|
||||
_buildDialButton('6'),
|
||||
_buildDialButton('4', Colors.white),
|
||||
_buildDialButton('5', Colors.white),
|
||||
_buildDialButton('6', Colors.white),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildDialButton('7'),
|
||||
_buildDialButton('8'),
|
||||
_buildDialButton('9'),
|
||||
_buildDialButton('7', Colors.white),
|
||||
_buildDialButton('8', Colors.white),
|
||||
_buildDialButton('9', Colors.white),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildDialButton('*'),
|
||||
_buildDialButton('0'),
|
||||
_buildDialButton('#'),
|
||||
_buildDialButton('*', const Color.fromRGBO(117, 117, 117, 1)),
|
||||
_buildDialButtonWithPlus('0'),
|
||||
_buildDialButton('#', const Color.fromRGBO(117, 117, 117, 1)),
|
||||
],
|
||||
),
|
||||
],
|
||||
@ -249,26 +259,28 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// Add Contact Button
|
||||
Positioned(
|
||||
bottom: 20.0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: AddContactButton(),
|
||||
child: ElevatedButton(
|
||||
onPressed: dialedNumber.isNotEmpty ? () => _makeCall(dialedNumber) : null,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green[700],
|
||||
shape: const CircleBorder(),
|
||||
padding: const EdgeInsets.all(20),
|
||||
),
|
||||
child: const Icon(Icons.phone, color: Colors.white, size: 30),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Top Row with Back Arrow
|
||||
Positioned(
|
||||
top: 40.0,
|
||||
left: 16.0,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -276,7 +288,7 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDialButton(String number) {
|
||||
Widget _buildDialButton(String number, Color textColor) {
|
||||
return ElevatedButton(
|
||||
onPressed: () => _onNumberPress(number),
|
||||
style: ElevatedButton.styleFrom(
|
||||
@ -286,11 +298,38 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
),
|
||||
child: Text(
|
||||
number,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
color: Colors.white,
|
||||
),
|
||||
style: TextStyle(fontSize: 24, color: textColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildDialButtonWithPlus(String number) {
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onLongPress: _onPlusPress,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _onNumberPress(number),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.black,
|
||||
shape: const CircleBorder(),
|
||||
padding: const EdgeInsets.all(16),
|
||||
),
|
||||
child: Text(
|
||||
number,
|
||||
style: const TextStyle(fontSize: 24, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
child: Text(
|
||||
'+',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ class HistoryPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HistoryPageState extends State<HistoryPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
|
||||
List<History> histories = [];
|
||||
bool loading = true;
|
||||
int? _expandedIndex;
|
||||
@ -47,10 +47,13 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
// Create a MethodChannel instance.
|
||||
static const MethodChannel _channel = MethodChannel('com.example.calllog');
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true; // Preserve state when switching pages
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (loading) {
|
||||
if (loading && histories.isEmpty) {
|
||||
_buildHistories();
|
||||
}
|
||||
}
|
||||
@ -149,9 +152,9 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
List<Contact> contacts = contactState.contacts;
|
||||
|
||||
List<History> callHistories = [];
|
||||
// Process each log entry.
|
||||
for (var entry in nativeLogs) {
|
||||
// Each entry is a Map with keys: number, type, date, duration.
|
||||
// Process each log entry with intermittent yields to avoid freezing.
|
||||
for (int i = 0; i < nativeLogs.length; i++) {
|
||||
final entry = nativeLogs[i];
|
||||
final String number = entry['number'] ?? '';
|
||||
if (number.isEmpty) continue;
|
||||
|
||||
@ -197,6 +200,8 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
|
||||
callHistories
|
||||
.add(History(matchedContact, callDate, callType, callStatus, 1));
|
||||
// Yield every 10 iterations to avoid blocking the UI.
|
||||
if (i % 10 == 0) await Future.delayed(Duration(milliseconds: 1));
|
||||
}
|
||||
|
||||
// Sort histories by most recent.
|
||||
@ -272,6 +277,7 @@ class _HistoryPageState extends State<HistoryPage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context); // required due to AutomaticKeepAliveClientMixin
|
||||
final contactState = ContactState.of(context);
|
||||
|
||||
if (loading || contactState.loading) {
|
||||
|
@ -10,53 +10,82 @@ import '../../services/contact_service.dart';
|
||||
import 'package:dialer/features/voicemail/voicemail_page.dart';
|
||||
import '../contacts/widgets/contact_modal.dart';
|
||||
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
List<Contact> _allContacts = [];
|
||||
List<Contact> _contactSuggestions = [];
|
||||
final ContactService _contactService = ContactService();
|
||||
final ObfuscateService _obfuscateService = ObfuscateService();
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
late SearchController _searchBarController;
|
||||
String _rawSearchInput = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Set the TabController length to 4
|
||||
_tabController = TabController(length: 4, vsync: this, initialIndex: 1);
|
||||
_tabController = TabController(length: 4, vsync: this, initialIndex: 2);
|
||||
_tabController.addListener(_handleTabIndex);
|
||||
_searchBarController = SearchController();
|
||||
_searchBarController.addListener(() {
|
||||
if (_searchController.text != _searchBarController.text) {
|
||||
_rawSearchInput = _searchBarController.text;
|
||||
_searchController.text = _rawSearchInput;
|
||||
_onSearchChanged(_searchBarController.text);
|
||||
}
|
||||
});
|
||||
_fetchContacts();
|
||||
}
|
||||
|
||||
void _fetchContacts() async {
|
||||
_allContacts = await _contactService.fetchContacts();
|
||||
setState(() {});
|
||||
_contactSuggestions = List.from(_allContacts);
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
void _clearSearch() {
|
||||
_searchController.clear();
|
||||
_searchBarController.clear();
|
||||
_rawSearchInput = '';
|
||||
_onSearchChanged('');
|
||||
}
|
||||
|
||||
void _onSearchChanged(String query) {
|
||||
setState(() {
|
||||
if (query.isEmpty) {
|
||||
_contactSuggestions = List.from(_allContacts); // Reset suggestions
|
||||
_contactSuggestions = List.from(_allContacts);
|
||||
} else {
|
||||
final normalizedQuery = _normalizeString(query.toLowerCase());
|
||||
_contactSuggestions = _allContacts.where((contact) {
|
||||
return contact.displayName
|
||||
.toLowerCase()
|
||||
.contains(query.toLowerCase());
|
||||
final normalizedName = _normalizeString(contact.displayName.toLowerCase());
|
||||
return normalizedName.contains(normalizedQuery);
|
||||
}).toList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _normalizeString(String input) {
|
||||
const accentMap = {
|
||||
'àáâãäå': 'a',
|
||||
'èéêë': 'e',
|
||||
'ìíîï': 'i',
|
||||
'òóôõö': 'o',
|
||||
'ùúûü': 'u',
|
||||
'ç': 'c',
|
||||
'ñ': 'n',
|
||||
};
|
||||
String normalized = input;
|
||||
accentMap.forEach((accents, base) {
|
||||
for (var accent in accents.split('')) {
|
||||
normalized = normalized.replaceAll(accent, base);
|
||||
}
|
||||
});
|
||||
return normalized;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_searchBarController.dispose();
|
||||
_tabController.removeListener(_handleTabIndex);
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
@ -69,19 +98,18 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
void _toggleFavorite(Contact contact) async {
|
||||
try {
|
||||
if (await FlutterContacts.requestPermission()) {
|
||||
Contact? fullContact = await FlutterContacts.getContact(contact.id,
|
||||
withProperties: true,
|
||||
withAccounts: true,
|
||||
withPhoto: true,
|
||||
withThumbnail: true);
|
||||
Contact? fullContact = await FlutterContacts.getContact(
|
||||
contact.id,
|
||||
withProperties: true,
|
||||
withAccounts: true,
|
||||
withPhoto: true,
|
||||
withThumbnail: true,
|
||||
);
|
||||
|
||||
if (fullContact != null) {
|
||||
fullContact.isStarred = !fullContact.isStarred;
|
||||
await FlutterContacts.updateContact(fullContact);
|
||||
setState(() {
|
||||
// Updating the contact list after toggling the favorite
|
||||
_fetchContacts();
|
||||
});
|
||||
_fetchContacts();
|
||||
}
|
||||
} else {
|
||||
print("Could not fetch contact details");
|
||||
@ -100,7 +128,6 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
backgroundColor: Colors.black,
|
||||
body: Column(
|
||||
children: [
|
||||
// Persistent Search Bar
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 24.0,
|
||||
@ -118,35 +145,33 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
border: Border.all(color: Colors.grey.shade800, width: 1),
|
||||
),
|
||||
child: SearchAnchor(
|
||||
builder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
searchController: _searchBarController,
|
||||
builder: (BuildContext context, SearchController controller) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
controller.openView(); // Open the search view
|
||||
controller.openView();
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color.fromARGB(255, 30, 30, 30),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade800, width: 1),
|
||||
border: Border.all(color: Colors.grey.shade800, width: 1),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 12.0, horizontal: 16.0),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.search,
|
||||
color: Colors.grey, size: 24.0),
|
||||
const Icon(Icons.search, color: Colors.grey, size: 24.0),
|
||||
const SizedBox(width: 8.0),
|
||||
Text(
|
||||
_searchController.text.isEmpty
|
||||
? 'Search contacts'
|
||||
: _searchController.text,
|
||||
style: const TextStyle(
|
||||
color: Colors.grey, fontSize: 16.0),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_rawSearchInput.isEmpty
|
||||
? 'Search contacts'
|
||||
: _rawSearchInput,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 16.0),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (_searchController.text.isNotEmpty)
|
||||
if (_rawSearchInput.isNotEmpty)
|
||||
GestureDetector(
|
||||
onTap: _clearSearch,
|
||||
child: const Icon(
|
||||
@ -161,23 +186,24 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
);
|
||||
},
|
||||
viewOnChanged: (query) {
|
||||
_onSearchChanged(query); // Update immediately
|
||||
|
||||
if (_searchBarController.text != query) {
|
||||
_rawSearchInput = query;
|
||||
_searchBarController.text = query;
|
||||
_searchController.text = query;
|
||||
}
|
||||
_onSearchChanged(query);
|
||||
},
|
||||
suggestionsBuilder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
suggestionsBuilder: (BuildContext context, SearchController controller) {
|
||||
return _contactSuggestions.map((contact) {
|
||||
return ListTile(
|
||||
key: ValueKey(contact.id),
|
||||
title: Text(_obfuscateService.obfuscateData(contact.displayName),
|
||||
style: const TextStyle(color: Colors.white)),
|
||||
title: Text(
|
||||
_obfuscateService.obfuscateData(contact.displayName),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
onTap: () {
|
||||
// Clear the search text input
|
||||
controller.text = '';
|
||||
|
||||
// Close the search view
|
||||
controller.closeView(contact.displayName);
|
||||
|
||||
// Show the ContactModal when a contact is tapped
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@ -186,34 +212,28 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
return ContactModal(
|
||||
contact: contact,
|
||||
onEdit: () async {
|
||||
if (await FlutterContacts
|
||||
.requestPermission()) {
|
||||
final updatedContact =
|
||||
await FlutterContacts
|
||||
.openExternalEdit(contact.id);
|
||||
if (await FlutterContacts.requestPermission()) {
|
||||
final updatedContact = await FlutterContacts
|
||||
.openExternalEdit(contact.id);
|
||||
if (updatedContact != null) {
|
||||
_fetchContacts();
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'${contact.displayName} updated successfully!'),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Edit canceled or failed.'),
|
||||
content: Text('Edit canceled or failed.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
onToggleFavorite: () =>
|
||||
_toggleFavorite(contact),
|
||||
onToggleFavorite: () => _toggleFavorite(contact),
|
||||
isFavorite: contact.isStarred,
|
||||
);
|
||||
},
|
||||
@ -225,7 +245,6 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
),
|
||||
),
|
||||
),
|
||||
// 3-dot menu
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert, color: Colors.white),
|
||||
itemBuilder: (BuildContext context) => [
|
||||
@ -238,8 +257,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
if (value == 'settings') {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SettingsPage()),
|
||||
MaterialPageRoute(builder: (context) => const SettingsPage()),
|
||||
);
|
||||
}
|
||||
},
|
||||
@ -247,7 +265,6 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
],
|
||||
),
|
||||
),
|
||||
// Main content with TabBarView
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
@ -322,4 +339,4 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
@override
|
||||
_MyHomePageState createState() => _MyHomePageState();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user