marco.pms.mobileapp/lib/view/dashboard/dashboard_screen.dart
Vaibhav Surve a0f1602f4e feat(directory): add contact profile and directory management features
- Implemented ContactProfileResponse and related models for handling contact details.
- Created ContactTagResponse and ContactTag models for managing contact tags.
- Added DirectoryCommentResponse and DirectoryComment models for comment management.
- Developed DirectoryFilterBottomSheet for filtering contacts.
- Introduced OrganizationListModel for organization data handling.
- Updated routes to include DirectoryMainScreen.
- Enhanced DashboardScreen to navigate to the new directory page.
- Created ContactDetailScreen for displaying detailed contact information.
- Developed DirectoryMainScreen for managing and displaying contacts.
- Added dependencies for font_awesome_flutter and flutter_html in pubspec.yaml.
2025-07-02 15:57:39 +05:30

321 lines
11 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:get/get.dart';
import 'package:marco/controller/dashboard/dashboard_controller.dart';
import 'package:marco/controller/project_controller.dart';
import 'package:marco/helpers/services/storage/local_storage.dart';
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
import 'package:marco/helpers/utils/my_shadow.dart';
import 'package:marco/helpers/widgets/my_button.dart';
import 'package:marco/helpers/widgets/my_card.dart';
import 'package:marco/helpers/widgets/my_container.dart';
import 'package:marco/helpers/widgets/my_spacing.dart';
import 'package:marco/helpers/widgets/my_text.dart';
import 'package:marco/view/dashboard/dashboard_chart.dart';
import 'package:marco/view/layouts/layout.dart';
class DashboardScreen extends StatefulWidget {
const DashboardScreen({super.key});
static const String dashboardRoute = "/dashboard";
static const String employeesRoute = "/dashboard/employees";
static const String projectsRoute = "/dashboard";
static const String attendanceRoute = "/dashboard/attendance";
static const String tasksRoute = "/dashboard/daily-task";
static const String dailyTasksRoute = "/dashboard/daily-task-planing";
static const String dailyTasksProgressRoute =
"/dashboard/daily-task-progress";
static const String directoryMainPageRoute = "/dashboard/directory-main-page";
@override
State<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
final DashboardController dashboardController =
Get.put(DashboardController());
bool hasMpin = true;
@override
void initState() {
super.initState();
_checkMpinStatus();
}
Future<void> _checkMpinStatus() async {
final bool mpinStatus = await LocalStorage.getIsMpin();
setState(() {
hasMpin = mpinStatus;
});
}
@override
Widget build(BuildContext context) {
return Layout(
child: SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MySpacing.height(12),
_buildDashboardStats(),
MySpacing.height(24),
GetBuilder<ProjectController>(
id: 'dashboard_controller',
builder: (projectController) {
final bool isProjectSelected =
projectController.selectedProject != null;
return Opacity(
opacity: isProjectSelected ? 1.0 : 0.4,
child: IgnorePointer(
ignoring: !isProjectSelected,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AttendanceDashboardChart(),
MySpacing.height(300),
],
),
),
);
},
),
if (!hasMpin) ...[
MyCard(
borderRadiusAll: 12,
paddingAll: 16,
shadow: MyShadow(elevation: 2),
color: Colors.red.withOpacity(0.05),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Icon(Icons.warning_amber_rounded,
color: Colors.redAccent, size: 28),
MySpacing.width(12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MyText.bodyMedium(
"MPIN Not Generated",
color: Colors.redAccent,
fontWeight: 700,
),
MySpacing.height(4),
MyText.bodySmall(
"To secure your account, please generate your MPIN now.",
color: contentTheme.onBackground.withOpacity(0.8),
),
MySpacing.height(10),
Align(
alignment: Alignment.center,
child: MyButton.rounded(
onPressed: () {
Get.toNamed("/auth/mpin-auth");
},
backgroundColor: contentTheme.brandRed,
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.lock_outline,
size: 18, color: Colors.white),
MySpacing.width(8),
MyText.bodyMedium(
"Generate MPIN",
color: Colors.white,
fontWeight: 600,
),
],
),
),
),
],
),
),
],
),
),
],
],
),
),
);
}
Widget _buildDashboardStats() {
final stats = [
_StatItem(LucideIcons.scan_face, "Attendance", contentTheme.success,
DashboardScreen.attendanceRoute),
_StatItem(LucideIcons.users, "Employees", contentTheme.warning,
DashboardScreen.employeesRoute),
_StatItem(LucideIcons.logs, "Daily Task Planing", contentTheme.info,
DashboardScreen.dailyTasksRoute),
_StatItem(LucideIcons.list_todo, "Daily Task Progress", contentTheme.info,
DashboardScreen.dailyTasksProgressRoute),
_StatItem(LucideIcons.folder, "Directory", contentTheme.info,
DashboardScreen.directoryMainPageRoute),
];
return GetBuilder<ProjectController>(
id: 'dashboard_controller',
builder: (controller) {
final bool isLoading = controller.isLoading.value;
final bool isProjectSelected = controller.selectedProject != null;
if (isLoading) {
return Wrap(
spacing: 10,
runSpacing: 10,
children: List.generate(
4,
(index) =>
_buildStatCardSkeleton(MediaQuery.of(context).size.width / 3),
),
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!isProjectSelected)
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: MyCard(
color: Colors.orange.withOpacity(0.1),
paddingAll: 12,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Icon(Icons.info_outline, color: Colors.orange),
MySpacing.width(8),
Expanded(
child: MyText.bodySmall(
"No projects assigned yet. Please contact your manager to get started.",
color: Colors.orange.shade800,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
LayoutBuilder(
builder: (context, constraints) {
double maxWidth = constraints.maxWidth;
int crossAxisCount = (maxWidth / 100).floor().clamp(2, 4);
double cardWidth =
(maxWidth - (crossAxisCount - 1) * 10) / crossAxisCount;
return Wrap(
spacing: 10,
runSpacing: 10,
children: stats
.map((stat) =>
_buildStatCard(stat, cardWidth, isProjectSelected))
.toList(),
);
},
),
],
);
},
);
}
Widget _buildStatCardSkeleton(double width) {
return MyCard.bordered(
width: width,
height: 100,
paddingAll: 5,
borderRadiusAll: 10,
border: Border.all(color: Colors.grey.withOpacity(0.15)),
shadow: MyShadow(elevation: 1.5, position: MyShadowPosition.bottom),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MyContainer.rounded(
paddingAll: 12,
color: Colors.grey.shade300,
child: const SizedBox(width: 18, height: 18),
),
MySpacing.height(8),
Container(
height: 12,
width: 60,
color: Colors.grey.shade300,
),
],
),
);
}
Widget _buildStatCard(_StatItem statItem, double width, bool isEnabled) {
return Opacity(
opacity: isEnabled ? 1.0 : 0.4,
child: IgnorePointer(
ignoring: !isEnabled,
child: InkWell(
onTap: () {
if (!isEnabled) {
Get.defaultDialog(
title: "No Project Selected",
middleText:
"You need to select a project before accessing this section.",
confirm: ElevatedButton(
onPressed: () => Get.back(),
child: const Text("OK"),
),
);
} else {
Get.toNamed(statItem.route);
}
},
borderRadius: BorderRadius.circular(10),
child: MyCard.bordered(
width: width,
height: 100,
paddingAll: 5,
borderRadiusAll: 10,
border: Border.all(color: Colors.grey.withOpacity(0.15)),
shadow: MyShadow(elevation: 1.5, position: MyShadowPosition.bottom),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildStatCardIcon(statItem),
MySpacing.height(8),
MyText.labelSmall(
statItem.title,
maxLines: 2,
overflow: TextOverflow.visible,
textAlign: TextAlign.center,
),
],
),
),
),
),
);
}
Widget _buildStatCardIcon(_StatItem statItem) {
return MyContainer.rounded(
paddingAll: 10,
color: statItem.color.withOpacity(0.1),
child: Icon(statItem.icon, size: 18, color: statItem.color),
);
}
}
class _StatItem {
final IconData icon;
final String title;
final Color color;
final String route;
_StatItem(this.icon, this.title, this.color, this.route);
}