feat: redesign behavior page, add fatigue monitoring and fix map controller
This commit is contained in:
498
lib/views/home/statistics/statistics_dashboard.dart
Normal file
498
lib/views/home/statistics/statistics_dashboard.dart
Normal file
@@ -0,0 +1,498 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_driver/constant/finance_design_system.dart';
|
||||
import 'package:sefer_driver/controller/gamification/gamification_controller.dart';
|
||||
import 'package:sefer_driver/controller/home/statistics/statistics_controller.dart';
|
||||
|
||||
import 'widgets/stat_summary_card.dart';
|
||||
import 'widgets/daily_goal_widget.dart';
|
||||
import 'widgets/level_progress_widget.dart';
|
||||
import 'widgets/today_chart_widget.dart';
|
||||
import 'widgets/weekly_chart_widget.dart';
|
||||
import 'widgets/monthly_chart_widget.dart';
|
||||
|
||||
class StatisticsDashboard extends StatelessWidget {
|
||||
StatisticsDashboard({super.key});
|
||||
|
||||
final GamificationController gamController =
|
||||
Get.put(GamificationController());
|
||||
final StatisticsController statsController =
|
||||
Get.put(StatisticsController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: FinanceDesignSystem.backgroundColor,
|
||||
body: GetBuilder<GamificationController>(
|
||||
builder: (gc) {
|
||||
if (gc.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: FinanceDesignSystem.primaryDark),
|
||||
);
|
||||
}
|
||||
|
||||
return CustomScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
slivers: [
|
||||
// ═══════ App Bar ═══════
|
||||
SliverAppBar(
|
||||
expandedHeight: 200,
|
||||
pinned: true,
|
||||
stretch: true,
|
||||
backgroundColor: FinanceDesignSystem.primaryDark,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new_rounded,
|
||||
color: Colors.white, size: 20),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh_rounded,
|
||||
color: Colors.white),
|
||||
onPressed: () => gc.fetchGamificationData(),
|
||||
),
|
||||
],
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
'Statistics'.tr,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
background: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: FinanceDesignSystem.balanceGradient,
|
||||
),
|
||||
),
|
||||
// أيقونة زخرفية
|
||||
Positioned(
|
||||
right: -40,
|
||||
top: -20,
|
||||
child: Icon(
|
||||
Icons.bar_chart_rounded,
|
||||
size: 200,
|
||||
color: Colors.white.withOpacity(0.04),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: -30,
|
||||
bottom: 20,
|
||||
child: Icon(
|
||||
Icons.emoji_events_rounded,
|
||||
size: 120,
|
||||
color: Colors.white.withOpacity(0.03),
|
||||
),
|
||||
),
|
||||
// بطاقة المستوى في الهيدر
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 40),
|
||||
Text(
|
||||
gc.currentLevel.emoji,
|
||||
style: const TextStyle(fontSize: 40),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
Get.locale?.languageCode == 'ar'
|
||||
? gc.currentLevel.nameAr
|
||||
: gc.currentLevel.nameEn,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${gc.unlockedCount}/${gc.totalAchievements} ${'Achievements'.tr}',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.5),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// ═══════ المحتوى ═══════
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 40),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
// 1. بطاقات الإحصائيات الأربعة
|
||||
_buildSummaryCards(gc),
|
||||
const SizedBox(
|
||||
height: FinanceDesignSystem.verticalSectionPadding),
|
||||
|
||||
// 2. الهدف اليومي
|
||||
DailyGoalWidget(controller: gc),
|
||||
const SizedBox(
|
||||
height: FinanceDesignSystem.verticalSectionPadding),
|
||||
|
||||
// 3. تقدم المستوى
|
||||
LevelProgressWidget(controller: gc),
|
||||
const SizedBox(
|
||||
height: FinanceDesignSystem.verticalSectionPadding),
|
||||
|
||||
// 4. إحصائيات اليوم
|
||||
TodayChartWidget(),
|
||||
const SizedBox(
|
||||
height: FinanceDesignSystem.verticalSectionPadding),
|
||||
|
||||
// 5. الرسم البياني الأسبوعي
|
||||
const WeeklyChartWidget(),
|
||||
const SizedBox(
|
||||
height: FinanceDesignSystem.verticalSectionPadding),
|
||||
|
||||
// 6. التقرير الشهري
|
||||
const MonthlyChartWidget(),
|
||||
const SizedBox(
|
||||
height: FinanceDesignSystem.verticalSectionPadding),
|
||||
|
||||
// 7. تقييم سلوك القيادة
|
||||
_buildBehaviorSection(gc),
|
||||
const SizedBox(
|
||||
height: FinanceDesignSystem.verticalSectionPadding),
|
||||
|
||||
// 8. الإنجازات
|
||||
_buildAchievementsSection(gc),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════ بطاقات الإحصائيات ═══════
|
||||
Widget _buildSummaryCards(GamificationController gc) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 1.5,
|
||||
children: [
|
||||
StatSummaryCard(
|
||||
icon: Icons.local_taxi_rounded,
|
||||
label: 'Total Trips'.tr,
|
||||
value: gc.totalTrips.toString(),
|
||||
color: FinanceDesignSystem.accentBlue,
|
||||
),
|
||||
StatSummaryCard(
|
||||
icon: Icons.star_rounded,
|
||||
label: 'Rating'.tr,
|
||||
value: gc.averageRating.toStringAsFixed(1),
|
||||
color: const Color(0xFFFFD700),
|
||||
),
|
||||
StatSummaryCard(
|
||||
icon: Icons.whatshot_rounded,
|
||||
label: 'Day Streak'.tr,
|
||||
value: '${gc.consecutiveDays}',
|
||||
color: const Color(0xFFFF5722),
|
||||
),
|
||||
StatSummaryCard(
|
||||
icon: Icons.people_rounded,
|
||||
label: 'Referrals'.tr,
|
||||
value: gc.totalReferrals.toString(),
|
||||
color: const Color(0xFF9C27B0),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════ قسم تقييم السلوك ═══════
|
||||
Widget _buildBehaviorSection(GamificationController gc) {
|
||||
bool isExcellent = gc.behaviorScore >= 90;
|
||||
bool isGood = gc.behaviorScore >= 75 && gc.behaviorScore < 90;
|
||||
|
||||
Color statusColor = isExcellent
|
||||
? Colors.green
|
||||
: isGood ? Colors.orange : Colors.red;
|
||||
|
||||
String statusText = isExcellent
|
||||
? 'Excellent'.tr
|
||||
: isGood ? 'Good'.tr : 'Needs Improvement'.tr;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.cardColor,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 10, offset: Offset(0, 4))],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.shield_rounded, color: FinanceDesignSystem.accentBlue),
|
||||
const SizedBox(width: 8),
|
||||
Text('Driving Behavior'.tr, style: FinanceDesignSystem.headingStyle),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: statusColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
statusText,
|
||||
style: TextStyle(
|
||||
color: statusColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_behaviorStatItem(
|
||||
title: 'Score'.tr,
|
||||
value: '${gc.behaviorScore}%',
|
||||
icon: Icons.speed_rounded,
|
||||
color: FinanceDesignSystem.accentBlue,
|
||||
),
|
||||
_behaviorStatItem(
|
||||
title: 'Max Speed'.tr,
|
||||
value: '${gc.maxSpeed.toStringAsFixed(0)} km/h',
|
||||
icon: Icons.directions_car_rounded,
|
||||
color: Colors.orange,
|
||||
),
|
||||
_behaviorStatItem(
|
||||
title: 'Hard Brakes'.tr,
|
||||
value: '${gc.hardBrakes}',
|
||||
icon: Icons.warning_rounded,
|
||||
color: Colors.red,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: LinearProgressIndicator(
|
||||
value: gc.behaviorScore / 100,
|
||||
backgroundColor: FinanceDesignSystem.backgroundColor,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(statusColor),
|
||||
minHeight: 8,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _behaviorStatItem({required String title, required String value, required IconData icon, required Color color}) {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(value, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: FinanceDesignSystem.primaryDark)),
|
||||
Text(title, style: const TextStyle(fontSize: 12, color: FinanceDesignSystem.textSecondary)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════ قسم الإنجازات ═══════
|
||||
Widget _buildAchievementsSection(GamificationController gc) {
|
||||
final unlockedAch =
|
||||
gc.achievements.where((a) => a.isUnlocked).toList();
|
||||
final lockedAch =
|
||||
gc.achievements.where((a) => !a.isUnlocked).toList();
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Achievements'.tr, style: FinanceDesignSystem.headingStyle),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.accentBlue.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
'${gc.unlockedCount}/${gc.totalAchievements}',
|
||||
style: const TextStyle(
|
||||
color: FinanceDesignSystem.accentBlue,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// الإنجازات المفتوحة
|
||||
if (unlockedAch.isNotEmpty) ...[
|
||||
...unlockedAch.map((a) => _buildAchievementCard(a, true)),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// الإنجازات المقفلة
|
||||
...lockedAch.map((a) => _buildAchievementCard(a, false)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAchievementCard(Achievement ach, bool unlocked) {
|
||||
final isAr = Get.locale?.languageCode == 'ar';
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: unlocked ? Colors.white : Colors.grey.shade50,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
border: unlocked
|
||||
? Border.all(color: ach.color.withOpacity(0.3), width: 1.5)
|
||||
: null,
|
||||
boxShadow: unlocked
|
||||
? [
|
||||
BoxShadow(
|
||||
color: ach.color.withOpacity(0.1),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// أيقونة الإنجاز
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: unlocked
|
||||
? ach.color.withOpacity(0.15)
|
||||
: Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Icon(
|
||||
ach.icon,
|
||||
color: unlocked ? ach.color : Colors.grey.shade400,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
|
||||
// المعلومات
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
isAr ? ach.titleAr : ach.titleEn,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
color: unlocked
|
||||
? FinanceDesignSystem.primaryDark
|
||||
: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
isAr ? ach.descriptionAr : ach.descriptionEn,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
if (!unlocked) ...[
|
||||
const SizedBox(height: 8),
|
||||
// شريط التقدم
|
||||
Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
FractionallySizedBox(
|
||||
widthFactor: ach.progress,
|
||||
child: Container(
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: ach.color.withOpacity(0.6),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${ach.currentProgress}/${ach.target}',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.grey.shade400,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// أيقونة الحالة
|
||||
if (unlocked)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: ach.color.withOpacity(0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.check_rounded,
|
||||
color: ach.color,
|
||||
size: 18,
|
||||
),
|
||||
)
|
||||
else
|
||||
Icon(
|
||||
Icons.lock_outline_rounded,
|
||||
color: Colors.grey.shade300,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
307
lib/views/home/statistics/widgets/daily_goal_widget.dart
Normal file
307
lib/views/home/statistics/widgets/daily_goal_widget.dart
Normal file
@@ -0,0 +1,307 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../../constant/finance_design_system.dart';
|
||||
import '../../../../controller/gamification/gamification_controller.dart';
|
||||
|
||||
class DailyGoalWidget extends StatelessWidget {
|
||||
final GamificationController controller;
|
||||
|
||||
const DailyGoalWidget({super.key, required this.controller});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.03),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: controller.isDailyGoalMet
|
||||
? FinanceDesignSystem.successGreen.withOpacity(0.1)
|
||||
: FinanceDesignSystem.accentBlue.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(
|
||||
controller.isDailyGoalMet
|
||||
? Icons.check_circle_rounded
|
||||
: Icons.track_changes_rounded,
|
||||
color: controller.isDailyGoalMet
|
||||
? FinanceDesignSystem.successGreen
|
||||
: FinanceDesignSystem.accentBlue,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Daily Goal'.tr,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: FinanceDesignSystem.primaryDark,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'الهدف اليومي'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// زر تعديل الهدف
|
||||
InkWell(
|
||||
onTap: () => _showSetGoalDialog(context),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
controller.dailyGoal > 0
|
||||
? 'Edit'.tr
|
||||
: 'Set Goal'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: FinanceDesignSystem.accentBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// مبلغ الأرباح والهدف
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Text(
|
||||
controller.dailyEarnings.toStringAsFixed(0),
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w900,
|
||||
color: controller.isDailyGoalMet
|
||||
? FinanceDesignSystem.successGreen
|
||||
: FinanceDesignSystem.primaryDark,
|
||||
fontFamily: 'digit',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'/ ${controller.dailyGoal.toStringAsFixed(0)} ${'SYP'.tr}',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade400,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// شريط التقدم
|
||||
Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: 12,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 800),
|
||||
curve: Curves.easeOutCubic,
|
||||
height: 12,
|
||||
width: constraints.maxWidth * controller.dailyGoalProgress,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: controller.isDailyGoalMet
|
||||
? [
|
||||
FinanceDesignSystem.successGreen,
|
||||
const Color(0xFF69F0AE)
|
||||
]
|
||||
: [
|
||||
FinanceDesignSystem.accentBlue,
|
||||
const Color(0xFF82B1FF)
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: (controller.isDailyGoalMet
|
||||
? FinanceDesignSystem.successGreen
|
||||
: FinanceDesignSystem.accentBlue)
|
||||
.withOpacity(0.3),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'${(controller.dailyGoalProgress * 100).toStringAsFixed(0)}%',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: controller.isDailyGoalMet
|
||||
? FinanceDesignSystem.successGreen
|
||||
: FinanceDesignSystem.accentBlue,
|
||||
),
|
||||
),
|
||||
if (controller.isDailyGoalMet)
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.celebration_rounded,
|
||||
color: Color(0xFFFFD700), size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Goal Achieved!'.tr,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: FinanceDesignSystem.successGreen,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
else
|
||||
Text(
|
||||
'${'Remaining:'.tr} ${(controller.dailyGoal - controller.dailyEarnings).clamp(0, double.infinity).toStringAsFixed(0)} ${'SYP'.tr}',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showSetGoalDialog(BuildContext context) {
|
||||
final textController = TextEditingController(
|
||||
text: controller.dailyGoal > 0
|
||||
? controller.dailyGoal.toStringAsFixed(0)
|
||||
: '',
|
||||
);
|
||||
|
||||
Get.defaultDialog(
|
||||
title: 'Set Daily Goal'.tr,
|
||||
titleStyle: FinanceDesignSystem.headingStyle,
|
||||
content: Column(
|
||||
children: [
|
||||
Text(
|
||||
'How much do you want to earn today?'.tr,
|
||||
style: FinanceDesignSystem.subHeadingStyle,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: textController,
|
||||
keyboardType: TextInputType.number,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: 'digit',
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: '5000',
|
||||
suffixText: 'SYP'.tr,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide:
|
||||
BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide:
|
||||
const BorderSide(color: FinanceDesignSystem.accentBlue),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// الأهداف السريعة
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: [1000, 3000, 5000, 10000].map((goal) {
|
||||
return ActionChip(
|
||||
label: Text('$goal'),
|
||||
labelStyle: const TextStyle(fontSize: 12),
|
||||
backgroundColor: FinanceDesignSystem.accentBlue.withOpacity(0.1),
|
||||
side: BorderSide.none,
|
||||
onPressed: () {
|
||||
textController.text = goal.toString();
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
confirm: ElevatedButton(
|
||||
onPressed: () {
|
||||
double? goal = double.tryParse(textController.text);
|
||||
if (goal != null && goal > 0) {
|
||||
controller.setDailyGoal(goal);
|
||||
Get.back();
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: FinanceDesignSystem.accentBlue,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 12),
|
||||
),
|
||||
child: Text('Save'.tr),
|
||||
),
|
||||
cancel: TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: Text('Cancel'.tr,
|
||||
style: const TextStyle(color: Colors.grey)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
93
lib/views/home/statistics/widgets/level_progress_widget.dart
Normal file
93
lib/views/home/statistics/widgets/level_progress_widget.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../../constant/finance_design_system.dart';
|
||||
import '../../../../controller/gamification/gamification_controller.dart';
|
||||
|
||||
class LevelProgressWidget extends StatelessWidget {
|
||||
final GamificationController controller;
|
||||
const LevelProgressWidget({super.key, required this.controller});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final level = controller.currentLevel;
|
||||
final next = controller.nextLevel;
|
||||
final isAr = Get.locale?.languageCode == 'ar';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [level.color.withOpacity(0.08), level.gradientEnd.withOpacity(0.04)],
|
||||
begin: Alignment.topLeft, end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
border: Border.all(color: level.color.withOpacity(0.2), width: 1.5),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Driver Level'.tr, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: FinanceDesignSystem.primaryDark)),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [level.color, level.gradientEnd]),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Text(level.emoji, style: const TextStyle(fontSize: 16)),
|
||||
const SizedBox(width: 6),
|
||||
Text(isAr ? level.nameAr : level.nameEn, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 13)),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: List.generate(DriverLevels.all.length, (i) {
|
||||
final lvl = DriverLevels.all[i];
|
||||
final isCurrent = lvl.id == level.id;
|
||||
final isPast = DriverLevels.all.indexOf(level) > i;
|
||||
return Expanded(child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 2), height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: isCurrent ? lvl.color : isPast ? lvl.color.withOpacity(0.6) : Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
));
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(children: DriverLevels.all.map((l) => Expanded(child: Text(l.emoji, textAlign: TextAlign.center, style: TextStyle(fontSize: l.id == level.id ? 16 : 12)))).toList()),
|
||||
const SizedBox(height: 16),
|
||||
if (next != null) ...[
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Text('${'Next Level:'.tr} ${isAr ? next.nameAr : next.nameEn}', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Colors.grey.shade700)),
|
||||
Text('${(controller.progressToNext * 100).toStringAsFixed(0)}%', style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: level.color)),
|
||||
]),
|
||||
const SizedBox(height: 8),
|
||||
Stack(children: [
|
||||
Container(height: 10, decoration: BoxDecoration(color: Colors.grey.shade100, borderRadius: BorderRadius.circular(5))),
|
||||
LayoutBuilder(builder: (ctx, c) => AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 800), curve: Curves.easeOutCubic, height: 10,
|
||||
width: c.maxWidth * controller.progressToNext,
|
||||
decoration: BoxDecoration(gradient: LinearGradient(colors: [level.color, level.gradientEnd]), borderRadius: BorderRadius.circular(5)),
|
||||
)),
|
||||
]),
|
||||
const SizedBox(height: 6),
|
||||
Text('${controller.totalPoints} / ${next.minPoints} ${'Points'.tr}', style: TextStyle(fontSize: 11, color: Colors.grey.shade500, fontFamily: 'digit')),
|
||||
] else
|
||||
Center(child: Text('🏆 ${'Maximum Level Reached!'.tr}', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: level.color))),
|
||||
const SizedBox(height: 16),
|
||||
Wrap(spacing: 6, runSpacing: 6, children: level.perks.map((p) => Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(color: level.color.withOpacity(0.1), borderRadius: BorderRadius.circular(12)),
|
||||
child: Text(p.tr, style: TextStyle(fontSize: 10, fontWeight: FontWeight.w600, color: level.color.withOpacity(0.8))),
|
||||
)).toList()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
99
lib/views/home/statistics/widgets/monthly_chart_widget.dart
Normal file
99
lib/views/home/statistics/widgets/monthly_chart_widget.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import '../../../../constant/finance_design_system.dart';
|
||||
import '../../../../controller/home/statistics/statistics_controller.dart';
|
||||
|
||||
class MonthlyChartWidget extends StatelessWidget {
|
||||
const MonthlyChartWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<StatisticsController>(
|
||||
builder: (sc) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 10, offset: const Offset(0, 4))],
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text('Monthly Report'.tr, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: FinanceDesignSystem.primaryDark)),
|
||||
const SizedBox(height: 16),
|
||||
// Summary Row
|
||||
Row(children: [
|
||||
_summaryTile('Total Earnings'.tr, '${sc.monthlyTotalEarnings.toStringAsFixed(0)} ${'SYP'.tr}', FinanceDesignSystem.successGreen),
|
||||
const SizedBox(width: 12),
|
||||
_summaryTile('Total Trips'.tr, '${sc.monthlyTotalTrips}', FinanceDesignSystem.accentBlue),
|
||||
const SizedBox(width: 12),
|
||||
_summaryTile('Best Day'.tr, '${sc.bestDay}', const Color(0xFFFFD700)),
|
||||
]),
|
||||
const SizedBox(height: 20),
|
||||
// Monthly Earnings Line Chart
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: sc.monthlyEarnings.isEmpty
|
||||
? Center(child: Text('No data yet'.tr, style: TextStyle(color: Colors.grey.shade400)))
|
||||
: LineChart(LineChartData(
|
||||
lineTouchData: LineTouchData(
|
||||
enabled: true,
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
getTooltipItems: (spots) => spots.map((s) => LineTooltipItem(
|
||||
'${s.y.toStringAsFixed(0)} ${'SYP'.tr}',
|
||||
const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12),
|
||||
)).toList(),
|
||||
),
|
||||
),
|
||||
gridData: FlGridData(show: true, drawVerticalLine: false,
|
||||
getDrawingHorizontalLine: (v) => FlLine(color: Colors.grey.shade100, strokeWidth: 1),
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, interval: 5,
|
||||
getTitlesWidget: (v, m) => Padding(padding: const EdgeInsets.only(top: 8),
|
||||
child: Text('${v.toInt()}', style: TextStyle(fontSize: 10, color: Colors.grey.shade500)),
|
||||
),
|
||||
)),
|
||||
leftTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
topTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
rightTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
spots: sc.monthlyEarnings.map((e) => FlSpot(e.day.toDouble(), e.pricePerDay)).toList(),
|
||||
isCurved: true, curveSmoothness: 0.3,
|
||||
color: FinanceDesignSystem.accentBlue, barWidth: 3,
|
||||
dotData: FlDotData(show: true, getDotPainter: (s, p, d, i) =>
|
||||
FlDotCirclePainter(radius: 3, color: FinanceDesignSystem.accentBlue, strokeWidth: 1, strokeColor: Colors.white),
|
||||
),
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter,
|
||||
colors: [FinanceDesignSystem.accentBlue.withOpacity(0.2), FinanceDesignSystem.accentBlue.withOpacity(0.0)],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _summaryTile(String label, String value, Color color) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(color: color.withOpacity(0.08), borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(children: [
|
||||
Text(value, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w800, color: color)),
|
||||
const SizedBox(height: 2),
|
||||
Text(label, style: TextStyle(fontSize: 9, color: Colors.grey.shade600), textAlign: TextAlign.center, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
83
lib/views/home/statistics/widgets/stat_summary_card.dart
Normal file
83
lib/views/home/statistics/widgets/stat_summary_card.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../constant/finance_design_system.dart';
|
||||
|
||||
class StatSummaryCard extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final String value;
|
||||
final Color color;
|
||||
|
||||
const StatSummaryCard({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.color,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.03),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
Icon(
|
||||
Icons.trending_up_rounded,
|
||||
color: Colors.grey.shade300,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w900,
|
||||
color: FinanceDesignSystem.primaryDark,
|
||||
fontFamily: 'digit',
|
||||
),
|
||||
),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.grey.shade500,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
57
lib/views/home/statistics/widgets/today_chart_widget.dart
Normal file
57
lib/views/home/statistics/widgets/today_chart_widget.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_driver/controller/home/captin/home_captain_controller.dart';
|
||||
import '../../../../constant/finance_design_system.dart';
|
||||
|
||||
class TodayChartWidget extends StatelessWidget {
|
||||
TodayChartWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<HomeCaptainController>(
|
||||
builder: (hc) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
boxShadow: [
|
||||
BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 10, offset: const Offset(0, 4)),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Today Overview'.tr, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: FinanceDesignSystem.primaryDark)),
|
||||
const SizedBox(height: 4),
|
||||
Text('نظرة عامة على اليوم'.tr, style: TextStyle(fontSize: 11, color: Colors.grey.shade500)),
|
||||
const SizedBox(height: 20),
|
||||
_buildRow(Icons.monetization_on_rounded, 'Earnings'.tr, '${hc.totalMoneyToday} ${'SYP'.tr}', FinanceDesignSystem.successGreen),
|
||||
const Divider(height: 24),
|
||||
_buildRow(Icons.local_taxi_rounded, 'Rides'.tr, hc.countRideToday, FinanceDesignSystem.accentBlue),
|
||||
const Divider(height: 24),
|
||||
Obx(() => _buildRow(Icons.timer_rounded, 'Online Duration'.tr, hc.totalDurationDisplay.value, const Color(0xFFFF9800))),
|
||||
const Divider(height: 24),
|
||||
_buildRow(Icons.cancel_outlined, 'Refused'.tr, hc.countRefuse, FinanceDesignSystem.dangerRed),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRow(IconData icon, String label, String value, Color color) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(color: color.withOpacity(0.1), borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(child: Text(label, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.grey.shade700))),
|
||||
Text(value, style: TextStyle(fontSize: 16, fontWeight: FontWeight.w800, color: FinanceDesignSystem.primaryDark, fontFamily: 'digit')),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
114
lib/views/home/statistics/widgets/weekly_chart_widget.dart
Normal file
114
lib/views/home/statistics/widgets/weekly_chart_widget.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import '../../../../constant/finance_design_system.dart';
|
||||
import '../../../../controller/home/statistics/statistics_controller.dart';
|
||||
|
||||
|
||||
class WeeklyChartWidget extends StatelessWidget {
|
||||
const WeeklyChartWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<StatisticsController>(
|
||||
builder: (sc) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 10, offset: const Offset(0, 4))],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Text('Weekly Earnings'.tr, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: FinanceDesignSystem.primaryDark)),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(color: FinanceDesignSystem.successGreen.withOpacity(0.1), borderRadius: BorderRadius.circular(12)),
|
||||
child: Text('${sc.weeklyEarnings.toStringAsFixed(0)} ${'SYP'.tr}', style: const TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: FinanceDesignSystem.successGreen)),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 8),
|
||||
Row(children: [
|
||||
_miniStat(Icons.local_taxi_rounded, '${sc.weeklyTrips}', 'Rides'.tr, FinanceDesignSystem.accentBlue),
|
||||
const SizedBox(width: 16),
|
||||
_miniStat(Icons.timer_rounded, '${sc.weeklyHours.toStringAsFixed(1)}h', 'Hours'.tr, const Color(0xFFFF9800)),
|
||||
]),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
height: 180,
|
||||
child: sc.weeklyStats.isEmpty
|
||||
? Center(child: Text('No data yet'.tr, style: TextStyle(color: Colors.grey.shade400)))
|
||||
: BarChart(
|
||||
BarChartData(
|
||||
alignment: BarChartAlignment.spaceAround,
|
||||
maxY: _getMaxY(sc.weeklyStats),
|
||||
barTouchData: BarTouchData(
|
||||
enabled: true,
|
||||
touchTooltipData: BarTouchTooltipData(
|
||||
getTooltipItem: (group, gi, rod, ri) => BarTooltipItem(
|
||||
'${rod.toY.toStringAsFixed(0)} ${'SYP'.tr}',
|
||||
const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
show: true,
|
||||
bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, getTitlesWidget: (v, m) {
|
||||
final idx = v.toInt();
|
||||
if (idx >= 0 && idx < sc.weeklyStats.length) {
|
||||
return Padding(padding: const EdgeInsets.only(top: 8), child: Text(sc.weeklyStats[idx].dayName.tr, style: TextStyle(fontSize: 10, color: Colors.grey.shade500)));
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
})),
|
||||
leftTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
topTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
rightTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
gridData: const FlGridData(show: false),
|
||||
barGroups: List.generate(sc.weeklyStats.length, (i) {
|
||||
final stat = sc.weeklyStats[i];
|
||||
final isToday = i == sc.weeklyStats.length - 1;
|
||||
return BarChartGroupData(x: i, barRods: [
|
||||
BarChartRodData(
|
||||
toY: stat.earnings,
|
||||
width: 20,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(6)),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.bottomCenter, end: Alignment.topCenter,
|
||||
colors: isToday
|
||||
? [FinanceDesignSystem.accentBlue, const Color(0xFF82B1FF)]
|
||||
: [FinanceDesignSystem.primaryDark.withOpacity(0.6), FinanceDesignSystem.primaryDark.withOpacity(0.3)],
|
||||
),
|
||||
),
|
||||
]);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _miniStat(IconData icon, String value, String label, Color color) {
|
||||
return Row(children: [
|
||||
Icon(icon, size: 16, color: color),
|
||||
const SizedBox(width: 4),
|
||||
Text(value, style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold, color: FinanceDesignSystem.primaryDark)),
|
||||
const SizedBox(width: 4),
|
||||
Text(label, style: TextStyle(fontSize: 11, color: Colors.grey.shade500)),
|
||||
]);
|
||||
}
|
||||
|
||||
double _getMaxY(List<DayStat> stats) {
|
||||
if (stats.isEmpty) return 100;
|
||||
final max = stats.map((s) => s.earnings).reduce((a, b) => a > b ? a : b);
|
||||
return max <= 0 ? 100 : max * 1.2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user