Separate buttons from alphabet_scroll_page.dart

This commit is contained in:
stcb 2024-11-08 11:42:57 +02:00
parent f3b22090d9
commit 7ebcd7eea4
4 changed files with 107 additions and 77 deletions

View 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)),
),
],
),
);
},
);
},
);
}
}

View File

@ -1,23 +1,16 @@
import 'package:dialer/widgets/username_color_generator.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:qr_flutter/qr_flutter.dart';
import '../contact_state.dart';
import 'add_contact_button.dart';
import 'share_own_qr.dart';
class AlphabetScrollPage extends StatefulWidget {
final List<Contact> contacts;
final double scrollOffset;
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
_AlphabetScrollPageState createState() => _AlphabetScrollPageState();
@ -40,7 +33,6 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
@override
Widget build(BuildContext context) {
// Build the alphabetized contact map
Map<String, List<Contact>> alphabetizedContacts = {};
for (var contact in widget.contacts) {
String firstLetter = contact.displayName.isNotEmpty ? contact.displayName[0].toUpperCase() : '#';
@ -55,76 +47,15 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
return Scaffold(
backgroundColor: Colors.black,
body: Column(
children: [
// Top buttons row
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,
)
AddContactButton(),
QRCodeButton(contacts: widget.contacts),
],
),
),

View 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,
);
}
}

View File

@ -1,5 +1,3 @@
// This is DEV
import 'package:dialer/features/home/home_page.dart';
import 'package:flutter/material.dart';
import 'package:dialer/features/contacts/contact_state.dart';