Separate buttons from alphabet_scroll_page.dart
This commit is contained in:
parent
f3b22090d9
commit
7ebcd7eea4
43
lib/features/contacts/widgets/add_contact_button.dart
Normal file
43
lib/features/contacts/widgets/add_contact_button.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class AddContactButton extends StatelessWidget {
|
||||||
|
const AddContactButton({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return 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)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +1,16 @@
|
|||||||
import 'package:dialer/widgets/username_color_generator.dart';
|
import 'package:dialer/widgets/username_color_generator.dart';
|
||||||
|
import 'package:flutter/foundation.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';
|
||||||
|
import 'add_contact_button.dart';
|
||||||
|
import 'share_own_qr.dart';
|
||||||
|
|
||||||
class AlphabetScrollPage extends StatefulWidget {
|
class AlphabetScrollPage extends StatefulWidget {
|
||||||
final List<Contact> contacts;
|
final List<Contact> contacts;
|
||||||
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();
|
||||||
@ -40,7 +33,6 @@ 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() : '#';
|
||||||
@ -55,76 +47,15 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [ // Top buttons row
|
||||||
// Top buttons row
|
|
||||||
Container(
|
Container(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
// Add Contact Button
|
AddContactButton(),
|
||||||
IconButton(
|
QRCodeButton(contacts: widget.contacts),
|
||||||
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,
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
58
lib/features/contacts/widgets/share_own_qr.dart
Normal file
58
lib/features/contacts/widgets/share_own_qr.dart
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_contacts/contact.dart';
|
||||||
|
import 'package:qr_flutter/qr_flutter.dart';
|
||||||
|
|
||||||
|
class QRCodeButton extends StatelessWidget {
|
||||||
|
final List<Contact> contacts;
|
||||||
|
|
||||||
|
const QRCodeButton({Key? key, required this.contacts}) : super(key: key);
|
||||||
|
|
||||||
|
Contact? getSelfContact() {
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint("Checking for self contact");
|
||||||
|
}
|
||||||
|
for (var contact in contacts) {
|
||||||
|
if (contact.groups.isNotEmpty) {
|
||||||
|
debugPrint("Contact ${contact.displayName} is in groups: ${contact.groups.map((group) => group.name).join(", ")}");
|
||||||
|
}
|
||||||
|
if (contact.groups.any((group) => group.name.toLowerCase() == "user")) {
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final selfContact = getSelfContact();
|
||||||
|
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(Icons.qr_code, color: selfContact != null ? Colors.blue : Colors.grey),
|
||||||
|
onPressed: selfContact != 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: selfContact.toVCard(),
|
||||||
|
version: QrVersions.auto,
|
||||||
|
backgroundColor: Colors.white, // Ensure QR code is visible on black background
|
||||||
|
size: 200.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
// This is DEV
|
|
||||||
|
|
||||||
import 'package:dialer/features/home/home_page.dart';
|
import 'package:dialer/features/home/home_page.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:dialer/features/contacts/contact_state.dart';
|
import 'package:dialer/features/contacts/contact_state.dart';
|
||||||
|
Loading…
Reference in New Issue
Block a user