390 lines
13 KiB
Dart
390 lines
13 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:flutter_html/flutter_html.dart';
|
|
import 'package:marco/controller/project_controller.dart';
|
|
import 'package:marco/controller/directory/directory_controller.dart';
|
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
|
import 'package:marco/helpers/widgets/my_text.dart';
|
|
import 'package:marco/model/directory/contact_model.dart';
|
|
import 'package:marco/helpers/widgets/avatar.dart';
|
|
import 'package:marco/helpers/utils/launcher_utils.dart';
|
|
import 'package:tab_indicator_styler/tab_indicator_styler.dart';
|
|
|
|
class ContactDetailScreen extends StatelessWidget {
|
|
final ContactModel contact;
|
|
|
|
const ContactDetailScreen({super.key, required this.contact});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final directoryController = Get.find<DirectoryController>();
|
|
final projectController = Get.find<ProjectController>();
|
|
|
|
Future.microtask(() {
|
|
if (!directoryController.contactCommentsMap.containsKey(contact.id)) {
|
|
directoryController.fetchCommentsForContact(contact.id);
|
|
}
|
|
});
|
|
|
|
return DefaultTabController(
|
|
length: 2,
|
|
child: Scaffold(
|
|
backgroundColor: const Color(0xFFF5F5F5),
|
|
appBar: _buildMainAppBar(projectController),
|
|
body: SafeArea(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildSubHeader(),
|
|
Expanded(
|
|
child: TabBarView(
|
|
children: [
|
|
_buildDetailsTab(directoryController, projectController),
|
|
_buildCommentsTab(directoryController),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
PreferredSizeWidget _buildMainAppBar(ProjectController projectController) {
|
|
return AppBar(
|
|
backgroundColor: const Color(0xFFF5F5F5),
|
|
elevation: 0.2,
|
|
automaticallyImplyLeading: false,
|
|
titleSpacing: 0,
|
|
title: Padding(
|
|
padding: MySpacing.xy(16, 0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios_new,
|
|
color: Colors.black, size: 20),
|
|
onPressed: () => Get.back(),
|
|
),
|
|
MySpacing.width(8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
MyText.titleLarge(
|
|
'Contact Profile',
|
|
fontWeight: 700,
|
|
color: Colors.black,
|
|
),
|
|
MySpacing.height(2),
|
|
GetBuilder<ProjectController>(
|
|
builder: (projectController) {
|
|
final projectName =
|
|
projectController.selectedProject?.name ??
|
|
'Select Project';
|
|
return Row(
|
|
children: [
|
|
const Icon(Icons.work_outline,
|
|
size: 14, color: Colors.grey),
|
|
MySpacing.width(4),
|
|
Expanded(
|
|
child: MyText.bodySmall(
|
|
projectName,
|
|
fontWeight: 600,
|
|
overflow: TextOverflow.ellipsis,
|
|
color: Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSubHeader() {
|
|
return Padding(
|
|
padding: MySpacing.xy(16, 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Avatar(
|
|
firstName: contact.name.split(" ").first,
|
|
lastName: contact.name.split(" ").length > 1
|
|
? contact.name.split(" ").last
|
|
: "",
|
|
size: 35,
|
|
backgroundColor: Colors.indigo,
|
|
),
|
|
MySpacing.width(12),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MyText.titleSmall(contact.name,
|
|
fontWeight: 600, color: Colors.black),
|
|
MySpacing.height(2),
|
|
MyText.bodySmall(contact.organization,
|
|
fontWeight: 500, color: Colors.grey[700]),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
TabBar(
|
|
labelColor: Colors.indigo,
|
|
unselectedLabelColor: Colors.grey,
|
|
indicator: MaterialIndicator(
|
|
color: Colors.indigo,
|
|
height: 4,
|
|
topLeftRadius: 8,
|
|
topRightRadius: 8,
|
|
bottomLeftRadius: 8,
|
|
bottomRightRadius: 8,
|
|
),
|
|
tabs: const [
|
|
Tab(text: "Details"),
|
|
Tab(text: "Comments"),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDetailsTab(DirectoryController directoryController,
|
|
ProjectController projectController) {
|
|
final email = contact.contactEmails.isNotEmpty
|
|
? contact.contactEmails.first.emailAddress
|
|
: "-";
|
|
|
|
final phone = contact.contactPhones.isNotEmpty
|
|
? contact.contactPhones.first.phoneNumber
|
|
: "-";
|
|
|
|
final createdDate = DateTime.now();
|
|
final formattedDate = DateFormat('MMMM dd, yyyy').format(createdDate);
|
|
final tags = contact.tags.map((e) => e.name).join(", ");
|
|
|
|
final bucketNames = contact.bucketIds
|
|
.map((id) => directoryController.contactBuckets
|
|
.firstWhereOrNull((b) => b.id == id)
|
|
?.name)
|
|
.whereType<String>()
|
|
.join(", ");
|
|
|
|
final projectNames = contact.projectIds
|
|
?.map((id) => projectController.projects
|
|
.firstWhereOrNull((p) => p.id == id)
|
|
?.name)
|
|
.whereType<String>()
|
|
.join(", ") ??
|
|
"-";
|
|
|
|
final category = contact.contactCategory?.name ?? "-";
|
|
|
|
return SingleChildScrollView(
|
|
padding: MySpacing.xy(8, 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_infoCard("Basic Info", [
|
|
_iconInfoRow(Icons.email, "Email", email,
|
|
onTap: () => LauncherUtils.launchEmail(email),
|
|
onLongPress: () =>
|
|
LauncherUtils.copyToClipboard(email, typeLabel: "Email")),
|
|
_iconInfoRow(Icons.phone, "Phone", phone,
|
|
onTap: () => LauncherUtils.launchPhone(phone),
|
|
onLongPress: () =>
|
|
LauncherUtils.copyToClipboard(phone, typeLabel: "Phone")),
|
|
_iconInfoRow(Icons.calendar_today, "Created", formattedDate),
|
|
_iconInfoRow(Icons.location_on, "Address", contact.address),
|
|
]),
|
|
_infoCard("Organization", [
|
|
_iconInfoRow(Icons.business, "Organization", contact.organization),
|
|
_iconInfoRow(Icons.category, "Category", category),
|
|
]),
|
|
_infoCard("Meta Info", [
|
|
_iconInfoRow(Icons.label, "Tags", tags.isNotEmpty ? tags : "-"),
|
|
_iconInfoRow(Icons.folder_shared, "Contact Buckets",
|
|
bucketNames.isNotEmpty ? bucketNames : "-"),
|
|
_iconInfoRow(Icons.work_outline, "Projects", projectNames),
|
|
]),
|
|
_infoCard("Description", [
|
|
MySpacing.height(6),
|
|
Align(
|
|
alignment: Alignment.topLeft,
|
|
child: MyText.bodyMedium(
|
|
contact.description,
|
|
color: Colors.grey[800],
|
|
maxLines: 10,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
),
|
|
])
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCommentsTab(DirectoryController directoryController) {
|
|
return Obx(() {
|
|
final comments = directoryController.contactCommentsMap[contact.id];
|
|
|
|
if (comments == null) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
if (comments.isEmpty) {
|
|
return Center(
|
|
child: MyText.bodyLarge("No comments yet.", color: Colors.grey));
|
|
}
|
|
|
|
return ListView.separated(
|
|
padding: MySpacing.xy(8, 8),
|
|
itemCount: comments.length,
|
|
separatorBuilder: (_, __) => MySpacing.height(12),
|
|
itemBuilder: (_, index) {
|
|
final comment = comments[index];
|
|
final initials = comment.createdBy.firstName.isNotEmpty
|
|
? comment.createdBy.firstName[0].toUpperCase()
|
|
: "?";
|
|
|
|
return Container(
|
|
padding: MySpacing.xy(14, 12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(12),
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
color: Colors.black12,
|
|
blurRadius: 4,
|
|
offset: Offset(0, 2),
|
|
)
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Avatar(firstName: initials, lastName: '', size: 31),
|
|
MySpacing.width(8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MyText.bodySmall("By: ${comment.createdBy.firstName}",
|
|
fontWeight: 600, color: Colors.indigo[700]),
|
|
MySpacing.height(2),
|
|
MyText.bodySmall(
|
|
DateFormat('dd MMM yyyy, hh:mm a')
|
|
.format(comment.createdAt),
|
|
fontWeight: 500,
|
|
color: Colors.grey[600],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.more_vert,
|
|
size: 20, color: Colors.grey),
|
|
onPressed: () {},
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(),
|
|
),
|
|
],
|
|
),
|
|
MySpacing.height(10),
|
|
Html(
|
|
data: comment.note,
|
|
style: {
|
|
"body": Style(
|
|
margin: Margins.all(0),
|
|
padding: HtmlPaddings.all(0),
|
|
fontSize: FontSize.medium,
|
|
color: Colors.black87,
|
|
),
|
|
"pre": Style(
|
|
padding: HtmlPaddings.all(8),
|
|
fontSize: FontSize.small,
|
|
fontFamily: 'monospace',
|
|
backgroundColor: const Color(0xFFF1F1F1),
|
|
border: Border.all(color: Colors.grey.shade300),
|
|
),
|
|
"h3": Style(
|
|
fontSize: FontSize.large,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.indigo[700],
|
|
),
|
|
"strong": Style(fontWeight: FontWeight.w700),
|
|
"p": Style(margin: Margins.only(bottom: 8)),
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
Widget _iconInfoRow(IconData icon, String label, String value,
|
|
{VoidCallback? onTap, VoidCallback? onLongPress}) {
|
|
return Padding(
|
|
padding: MySpacing.y(8),
|
|
child: GestureDetector(
|
|
onTap: onTap,
|
|
onLongPress: onLongPress,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(icon, size: 22, color: Colors.indigo),
|
|
MySpacing.width(12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MyText.bodySmall(label,
|
|
fontWeight: 600, color: Colors.black87),
|
|
MySpacing.height(2),
|
|
MyText.bodyMedium(value, color: Colors.grey[800]),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _infoCard(String title, List<Widget> children) {
|
|
return Card(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
elevation: 2,
|
|
margin: MySpacing.bottom(12),
|
|
child: Padding(
|
|
padding: MySpacing.xy(16, 16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MyText.titleSmall(title,
|
|
fontWeight: 700, color: Colors.indigo[700]),
|
|
MySpacing.height(8),
|
|
...children,
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|