marco.pms.mobileapp/lib/view/dashboard/dashboard_screen.dart

156 lines
4.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:get/get.dart';
import 'package:marco/helpers/theme/app_theme.dart';
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
import 'package:marco/helpers/utils/my_shadow.dart';
import 'package:marco/helpers/widgets/my_breadcrumb.dart';
import 'package:marco/helpers/widgets/my_breadcrumb_item.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/layouts/layout.dart';
class DashboardScreen extends StatelessWidget with UIMixin {
DashboardScreen({super.key});
@override
Widget build(BuildContext context) {
return Layout(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: MySpacing.x(flexSpacing),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MyText.titleMedium("Dashboard", fontSize: 18, fontWeight: 600),
MyBreadcrumb(children: [MyBreadcrumbItem(name: 'Dashboard')]),
],
),
),
MySpacing.height(flexSpacing),
Padding(
padding: MySpacing.x(flexSpacing / 2),
child: Column(
children: _dashboardStats().map((rowStats) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: rowStats,
);
}).toList(),
),
),
],
),
);
}
List<List<Widget>> _dashboardStats() {
final stats = [
{
"icon": LucideIcons.layout_dashboard,
"title": "Dashboard",
"route": "/dashboard/attendance",
"color": contentTheme.primary
},
{
"icon": LucideIcons.folder,
"title": "Projects",
"route": "/dashboard/attendance",
"color": contentTheme.secondary
},
{
"icon": LucideIcons.check,
"title": "Attendence",
"route": "/dashboard/attendance",
"color": contentTheme.success
},
{
"icon": LucideIcons.users,
"title": "Task",
"route": "/dashboard/attendance",
"color": contentTheme.info
},
];
// Group the stats into pairs for rows
List<List<Widget>> rows = [];
for (int i = 0; i < stats.length; i += 2) {
rows.add([
_buildStatCard(
icon: stats[i]['icon'] as IconData,
title: stats[i]['title'] as String,
route: stats[i]['route'] as String,
color: stats[i]['color'] as Color,
),
if (i + 1 < stats.length) _buildStatCard(
icon: stats[i + 1]['icon'] as IconData,
title: stats[i + 1]['title'] as String,
route: stats[i + 1]['route'] as String,
color: stats[i + 1]['color'] as Color,
),
]);
}
return rows;
}
Widget _buildStatCard({
required IconData icon,
required String title,
required String route,
required Color color,
String count = "",
String change = "",
}) {
return Expanded(
child: InkWell(
onTap: () => Get.toNamed(route),
child: MyCard.bordered(
borderRadiusAll: 10,
border: Border.all(color: Colors.grey.withOpacity(0.2)),
shadow: MyShadow(elevation: 1, position: MyShadowPosition.bottom),
paddingAll: 24,
height: 140,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MyContainer(
paddingAll: 16,
color: color.withOpacity(0.2),
child: MyContainer(
paddingAll: 8,
color: color,
child: Icon(icon, size: 16, color: contentTheme.light),
),
),
MySpacing.height(12),
MyText.labelSmall(title, maxLines: 1),
if (count.isNotEmpty)
MyText.bodyMedium(count, fontWeight: 600, maxLines: 1),
if (change.isNotEmpty)
Padding(
padding: MySpacing.top(8),
child: MyContainer(
padding: MySpacing.xy(6, 4),
color: change.startsWith('+')
? Colors.green.withOpacity(0.2)
: theme.colorScheme.error.withOpacity(0.2),
child: MyText.labelSmall(
change,
color: change.startsWith('+')
? Colors.green
: theme.colorScheme.error,
),
),
),
],
),
),
),
);
}
}