EssenceDailyCore/lib/pages/insights_page.dart

290 lines
10 KiB
Dart

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import '../models/task_item.dart';
import '../services/database_service.dart';
class InsightsPage extends StatelessWidget {
const InsightsPage({super.key});
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: DatabaseService.getTasksBox().listenable(),
builder: (context, Box<TaskItem> box, _) {
final completedTasks = box.values.where((t) => t.isCompleted).length;
// Mock data for graphs
final weeklyData = [0.3, 0.5, 0.2, 0.8, 0.6, 0.9, 0.4];
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Insights",
style: TextStyle(fontSize: 32, fontWeight: FontWeight.w900),
),
const SizedBox(height: 24),
// 1. Primary Stats Card
Container(
width: double.infinity,
padding: const EdgeInsets.all(28),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF2C2C2C), Color(0xFF000000)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(28),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: 20,
offset: const Offset(0, 10),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"TOTAL COMPLETED",
style: TextStyle(
color: Colors.white.withOpacity(0.6),
fontSize: 11,
fontWeight: FontWeight.bold,
letterSpacing: 1,
),
),
const Icon(
Icons.auto_graph_rounded,
color: Color(0xFFFF7F50),
size: 24,
),
],
),
const SizedBox(height: 20),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"$completedTasks",
style: const TextStyle(
color: Colors.white,
fontSize: 48,
fontWeight: FontWeight.w700,
height: 1,
),
),
const SizedBox(width: 8),
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
"Tasks",
style: TextStyle(
color: Colors.white.withOpacity(0.6),
fontSize: 16,
),
),
),
],
),
const SizedBox(height: 24),
// Weekly Velocity Bars
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: List.generate(7, (index) {
return Column(
children: [
Container(
width: 6,
height: 40 * weeklyData[index],
decoration: BoxDecoration(
color: index == 5
? const Color(0xFFFF7F50)
: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(4),
),
),
const SizedBox(height: 6),
Text(
['M', 'T', 'W', 'T', 'F', 'S', 'S'][index],
style: TextStyle(
color: Colors.white.withOpacity(0.4),
fontSize: 10,
),
),
],
);
}),
)
],
),
),
const SizedBox(height: 32),
// 2. Detailed Grid Stats
Row(
children: [
Expanded(
child: _buildInfoCard(
context,
"Avg / Day",
"4.2",
Icons.speed,
),
),
const SizedBox(width: 16),
Expanded(
child: _buildInfoCard(
context,
"Focus Time",
"12h",
Icons.timer_outlined,
),
),
],
),
const SizedBox(height: 32),
const Text(
"ACTIVITY HEATMAP",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey,
letterSpacing: 1,
),
),
const SizedBox(height: 16),
// 3. Heatmap
Wrap(
spacing: 8,
runSpacing: 8,
children: List.generate(28, (index) {
final opacity =
[0.05, 0.15, 0.3, 0.1, 0.6][Random().nextInt(5)];
return Container(
width: (MediaQuery.of(context).size.width - 56 - 48) / 7,
height: (MediaQuery.of(context).size.width - 56 - 48) / 7,
decoration: BoxDecoration(
color: const Color(0xFFFF7F50).withOpacity(opacity),
borderRadius: BorderRadius.circular(6),
),
);
}),
),
const SizedBox(height: 32),
const Text(
"PRODUCTIVITY TRENDS",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.grey,
letterSpacing: 1,
),
),
const SizedBox(height: 16),
_buildTrendRow("Weekly Completion", "+12%", isPositive: true),
_buildTrendRow("Focus Intensity", "-5%", isPositive: false),
],
),
),
),
);
},
);
}
Widget _buildInfoCard(
BuildContext context,
String title,
String value,
IconData icon,
) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 15,
offset: const Offset(0, 5),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon, size: 24, color: Colors.grey.shade400),
const SizedBox(height: 16),
Text(
value,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
const SizedBox(height: 4),
Text(
title,
style: TextStyle(
fontSize: 12,
color: Colors.grey.shade400,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
Widget _buildTrendRow(String title, String value, {bool isPositive = true}) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: isPositive
? Colors.green.withOpacity(0.1)
: Colors.red.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
),
child: Text(
value,
style: TextStyle(
color: isPositive ? Colors.green.shade700 : Colors.red.shade700,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
),
],
),
);
}
}