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 {
|
||||||
@ -9,6 +10,15 @@ class AlphabetScrollPage extends StatefulWidget {
|
|||||||
|
|
||||||
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,7 +52,85 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
|
|
||||||
List<String> alphabetKeys = alphabetizedContacts.keys.toList()..sort();
|
List<String> alphabetKeys = alphabetizedContacts.keys.toList()..sort();
|
||||||
|
|
||||||
return ListView.builder(
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
// Top buttons row
|
||||||
|
Container(
|
||||||
|
color: Colors.black,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
// Add Contact Button
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.add, color: Colors.blue),
|
||||||
|
onPressed: () {
|
||||||
|
// 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,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Contact List
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
itemCount: alphabetKeys.length,
|
itemCount: alphabetKeys.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
@ -50,6 +139,7 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
// Alphabet Letter Header
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -57,9 +147,11 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 28,
|
fontSize: 28,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// Contact Entries
|
||||||
...contacts.map((contact) {
|
...contacts.map((contact) {
|
||||||
String phoneNumber = contact.phones.isNotEmpty ? contact.phones.first.number : 'No phone number';
|
String phoneNumber = contact.phones.isNotEmpty ? contact.phones.first.number : 'No phone number';
|
||||||
Color avatarColor = generateColorFromName(contact.displayName);
|
Color avatarColor = generateColorFromName(contact.displayName);
|
||||||
@ -75,8 +167,8 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
style: TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
title: Text(contact.displayName),
|
title: Text(contact.displayName, style: TextStyle(color: Colors.white)),
|
||||||
subtitle: Text(phoneNumber),
|
subtitle: Text(phoneNumber, style: TextStyle(color: Colors.white70)),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Handle contact tap
|
// Handle contact tap
|
||||||
},
|
},
|
||||||
@ -85,6 +177,10 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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