Add contact page two upper buttons: share QrCode and tobeimplemented
This commit is contained in:
parent
a1ef168063
commit
f3b22090d9
@ -41,7 +41,6 @@ class _ContactStateState extends State<ContactState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<void> addNewContact(Contact contact) async {
|
Future<void> addNewContact(Contact contact) async {
|
||||||
await _contactService.addNewContact(contact);
|
await _contactService.addNewContact(contact);
|
||||||
await _fetchContacts();
|
await _fetchContacts();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:dialer/widgets/username_color_generator.dart';
|
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 'package:qr_flutter/qr_flutter.dart';
|
||||||
import '../contact_state.dart';
|
import '../contact_state.dart';
|
||||||
|
|
||||||
class AlphabetScrollPage extends StatefulWidget {
|
class AlphabetScrollPage extends StatefulWidget {
|
||||||
@ -8,6 +9,15 @@ class AlphabetScrollPage extends StatefulWidget {
|
|||||||
final double scrollOffset;
|
final double scrollOffset;
|
||||||
|
|
||||||
const AlphabetScrollPage({Key? key, required this.contacts, required this.scrollOffset}) : super(key: key);
|
const AlphabetScrollPage({Key? key, required this.contacts, required this.scrollOffset}) : super(key: key);
|
||||||
|
|
||||||
|
Contact? getSelfContact() {
|
||||||
|
for (var contact in contacts) {
|
||||||
|
if (contact.displayName.toLowerCase() == "user") {
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_AlphabetScrollPageState createState() => _AlphabetScrollPageState();
|
_AlphabetScrollPageState createState() => _AlphabetScrollPageState();
|
||||||
@ -30,6 +40,7 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// Build the alphabetized contact map
|
||||||
Map<String, List<Contact>> alphabetizedContacts = {};
|
Map<String, List<Contact>> alphabetizedContacts = {};
|
||||||
for (var contact in widget.contacts) {
|
for (var contact in widget.contacts) {
|
||||||
String firstLetter = contact.displayName.isNotEmpty ? contact.displayName[0].toUpperCase() : '#';
|
String firstLetter = contact.displayName.isNotEmpty ? contact.displayName[0].toUpperCase() : '#';
|
||||||
@ -41,50 +52,135 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
|
|
||||||
List<String> alphabetKeys = alphabetizedContacts.keys.toList()..sort();
|
List<String> alphabetKeys = alphabetizedContacts.keys.toList()..sort();
|
||||||
|
|
||||||
return ListView.builder(
|
return Scaffold(
|
||||||
controller: _scrollController,
|
backgroundColor: Colors.black,
|
||||||
itemCount: alphabetKeys.length,
|
body: Column(
|
||||||
itemBuilder: (context, index) {
|
children: [
|
||||||
String letter = alphabetKeys[index];
|
// Top buttons row
|
||||||
List<Contact> contacts = alphabetizedContacts[letter]!;
|
Container(
|
||||||
return Column(
|
color: Colors.black,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||||
children: [
|
child: Row(
|
||||||
Padding(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
|
children: [
|
||||||
child: Text(
|
// Add Contact Button
|
||||||
letter,
|
IconButton(
|
||||||
style: TextStyle(
|
icon: Icon(Icons.add, color: Colors.blue),
|
||||||
fontSize: 28,
|
onPressed: () {
|
||||||
fontWeight: FontWeight.bold,
|
// Show pop-up with two mock choices
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: true, // Allows dismissal by tapping outside
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
// Action for Option 1
|
||||||
|
},
|
||||||
|
child: Text("Option 1", style: TextStyle(color: Colors.white)),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
// Action for Option 2
|
||||||
|
},
|
||||||
|
child: Text("Option 2", style: TextStyle(color: Colors.white)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
// QR Code Button
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.qr_code, color: widget.getSelfContact() != null ? Colors.blue : Colors.grey),
|
||||||
|
|
||||||
|
onPressed: widget.getSelfContact() != null ? () {
|
||||||
|
showDialog(
|
||||||
|
barrierColor: Colors.white24,
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: true,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
content: SizedBox(
|
||||||
|
width: 200,
|
||||||
|
height: 220,
|
||||||
|
child: QrImageView(
|
||||||
|
data: widget.getSelfContact()!.toVCard(),
|
||||||
|
version: QrVersions.auto,
|
||||||
|
backgroundColor: Colors.white, // Ensure QR code is visible on black background
|
||||||
|
size: 200.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}: null,
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
...contacts.map((contact) {
|
),
|
||||||
String phoneNumber = contact.phones.isNotEmpty ? contact.phones.first.number : 'No phone number';
|
// Contact List
|
||||||
Color avatarColor = generateColorFromName(contact.displayName);
|
Expanded(
|
||||||
return ListTile(
|
child: ListView.builder(
|
||||||
leading: (contact.thumbnail != null && contact.thumbnail!.isNotEmpty)
|
controller: _scrollController,
|
||||||
? CircleAvatar(
|
itemCount: alphabetKeys.length,
|
||||||
backgroundImage: MemoryImage(contact.thumbnail!),
|
itemBuilder: (context, index) {
|
||||||
)
|
String letter = alphabetKeys[index];
|
||||||
: CircleAvatar(
|
List<Contact> contacts = alphabetizedContacts[letter]!;
|
||||||
backgroundColor: avatarColor,
|
return Column(
|
||||||
child: Text(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
contact.displayName.isNotEmpty ? contact.displayName[0].toUpperCase() : '?',
|
children: [
|
||||||
style: TextStyle(color: Colors.white),
|
// Alphabet Letter Header
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
|
||||||
|
child: Text(
|
||||||
|
letter,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 28,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
title: Text(contact.displayName),
|
),
|
||||||
subtitle: Text(phoneNumber),
|
// Contact Entries
|
||||||
onTap: () {
|
...contacts.map((contact) {
|
||||||
// Handle contact tap
|
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: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: Text(contact.displayName, style: TextStyle(color: Colors.white)),
|
||||||
|
subtitle: Text(phoneNumber, style: TextStyle(color: Colors.white70)),
|
||||||
|
onTap: () {
|
||||||
|
// Handle contact tap
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
qr_flutter: ^4.1.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user