Update: 2026-08-08 12:58:16
This commit is contained in:
@@ -12,7 +12,7 @@ import 'package:siro_driver/main.dart';
|
||||
import 'package:siro_driver/views/Rate/rate_app_page.dart';
|
||||
import 'package:siro_driver/views/auth/captin/contact_us_page.dart';
|
||||
import 'package:siro_driver/views/auth/captin/invite_driver_screen.dart';
|
||||
import 'package:siro_driver/views/home/statistics/statistics_dashboard.dart';
|
||||
import 'package:siro_driver/views/home/statistics/earnings_page.dart';
|
||||
import 'package:siro_driver/views/gamification/challenges_page.dart';
|
||||
import 'package:siro_driver/views/gamification/leaderboard_page.dart';
|
||||
import 'package:siro_driver/views/home/journal/schedule_page.dart';
|
||||
@@ -67,12 +67,12 @@ class AppDrawer extends StatelessWidget {
|
||||
title: 'Balance'.tr,
|
||||
icon: Icons.account_balance_wallet,
|
||||
color: Colors.green,
|
||||
onTap: () => Get.to(() => WalletCaptainRefactored())),
|
||||
onTap: () => Get.to(() => const WalletCaptainRefactored())),
|
||||
DrawerItem(
|
||||
title: 'Statistics'.tr,
|
||||
icon: Icons.bar_chart_rounded,
|
||||
color: Colors.deepPurple,
|
||||
onTap: () => Get.to(() => StatisticsDashboard())),
|
||||
title: 'أرباحي',
|
||||
icon: Icons.payments_rounded,
|
||||
color: Colors.teal,
|
||||
onTap: () => Get.to(() => EarningsPage())),
|
||||
DrawerItem(
|
||||
title: 'Challenges'.tr,
|
||||
icon: Icons.bolt_rounded,
|
||||
|
||||
@@ -16,7 +16,7 @@ import '../../../../../controller/functions/crud.dart';
|
||||
import '../../../../../controller/home/captin/order_request_controller.dart';
|
||||
import '../../../../../print.dart';
|
||||
import '../../../../Rate/ride_calculate_driver.dart';
|
||||
import 'package:siro_driver/views/home/statistics/statistics_dashboard.dart';
|
||||
import 'package:siro_driver/views/home/statistics/earnings_page.dart';
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Design Tokens (Responsive)
|
||||
@@ -103,7 +103,7 @@ GetBuilder<HomeCaptainController> leftMainMenuCaptainIcons() {
|
||||
color: _T.blue,
|
||||
tooltip: 'Statistics'.tr,
|
||||
onTap: () {
|
||||
Get.to(() => StatisticsDashboard());
|
||||
Get.to(() => EarningsPage());
|
||||
},
|
||||
onLongPress: () =>
|
||||
box.write(BoxName.statusDriverLocation, 'off'),
|
||||
|
||||
@@ -26,14 +26,29 @@ import 'widgets/financial_summary_card.dart';
|
||||
import 'widgets/promo_gamification_card.dart';
|
||||
import 'widgets/transaction_preview_item.dart';
|
||||
|
||||
class WalletCaptainRefactored extends StatelessWidget {
|
||||
WalletCaptainRefactored({super.key});
|
||||
class WalletCaptainRefactored extends StatefulWidget {
|
||||
const WalletCaptainRefactored({super.key});
|
||||
|
||||
@override
|
||||
State<WalletCaptainRefactored> createState() =>
|
||||
_WalletCaptainRefactoredState();
|
||||
}
|
||||
|
||||
class _WalletCaptainRefactoredState extends State<WalletCaptainRefactored> {
|
||||
final CaptainWalletController controller = Get.put(CaptainWalletController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
void initState() {
|
||||
super.initState();
|
||||
// كان التحديث يُنادى داخل build. وbuild يعمل عشرات المرات — عند كل
|
||||
// إعادة رسم، وكل تغيّر حالة، وكل دوران للشاشة — فكان كل واحدة منها
|
||||
// تُطلق نداءات شبكية. مكانه هنا: مرة واحدة عند فتح الشاشة، والباقي
|
||||
// بالسحب للتحديث أو بزر التحديث.
|
||||
controller.refreshCaptainWallet();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: FinanceDesignSystem.backgroundColor,
|
||||
appBar: AppBar(
|
||||
|
||||
@@ -0,0 +1,729 @@
|
||||
// earnings_page.dart — شاشة أرباح السائق
|
||||
//
|
||||
// الترتيب مقصود ويخالف الشاشة السابقة: **اليوم أولاً**. الشاشة القديمة
|
||||
// كانت تبدأ بترويسة زخرفية بارتفاع ٢٠٠ ثم تبويبَي أسبوعي/شهري — والسائق
|
||||
// يفتح الشاشة ليعرف كم كسب اليوم، لا ليقرأ تقريراً شهرياً.
|
||||
//
|
||||
// ثم الاقتطاعات، ثم أسبوعه، ثم تفصيل كل رحلة.
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_driver/constant/currency.dart';
|
||||
import 'package:siro_driver/constant/finance_design_system.dart';
|
||||
import 'package:siro_driver/controller/gamification/gamification_controller.dart';
|
||||
import 'package:siro_driver/controller/home/statistics/earnings_controller.dart';
|
||||
import 'package:siro_driver/controller/home/statistics/earnings_models.dart';
|
||||
|
||||
import 'widgets/behavior_and_achievements.dart';
|
||||
import 'widgets/daily_goal_widget.dart';
|
||||
import 'widgets/level_progress_widget.dart';
|
||||
import 'widgets/stat_summary_card.dart';
|
||||
|
||||
class EarningsPage extends StatelessWidget {
|
||||
EarningsPage({super.key});
|
||||
|
||||
// Get.put هنا لا في build: الشاشة السابقة كانت تنادي التحديث داخل
|
||||
// build، وbuild يعمل عشرات المرات — أي نداء شبكي مع كل إعادة رسم.
|
||||
final EarningsController c = Get.put(EarningsController());
|
||||
final GamificationController gam = Get.put(GamificationController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: FinanceDesignSystem.backgroundColor,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
title: Text('أرباحي',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: FinanceDesignSystem.primaryDark)),
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.arrow_back_ios_new_rounded,
|
||||
color: FinanceDesignSystem.primaryDark, size: 20),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
),
|
||||
body: GetBuilder<EarningsController>(
|
||||
builder: (ctl) {
|
||||
if (ctl.isLoading && ctl.summary == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
// لا بيانات ولا كاش: نعرض الخطأ صريحاً مع زر إعادة. الشاشة
|
||||
// السابقة كانت تعرض سبعة أيام بأصفار في هذه الحالة — فيرى
|
||||
// السائق دخله وقد تبخّر، وهي أسوأ رسالة يمكن أن يتلقّاها.
|
||||
if (ctl.summary == null) {
|
||||
return _errorState(ctl);
|
||||
}
|
||||
|
||||
final s = ctl.summary!;
|
||||
|
||||
// الترتيب هو القرار الأهم في هذه الشاشة بعد دمج الإحصائيات
|
||||
// فيها: **المال أولاً، ثم التقدّم**. السائق يفتحها ليعرف كم
|
||||
// كسب، لا ليرى مستواه — ووضع التلعيب قبل الأرباح كان يجعله
|
||||
// يمرّر ثلاث شاشات ليصل إلى ما جاء من أجله.
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await ctl.load(force: true);
|
||||
await gam.fetchGamificationData(force: true);
|
||||
},
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: FinanceDesignSystem.horizontalPadding,
|
||||
vertical: 8),
|
||||
children: [
|
||||
if (ctl.errorMessage != null) _staleBanner(ctl),
|
||||
_todayCard(s, ctl),
|
||||
const SizedBox(height: 16),
|
||||
if (s.deductions.hasAny) ...[
|
||||
_deductionsCard(s.deductions),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
_weekCard(s, ctl),
|
||||
const SizedBox(height: 16),
|
||||
_monthCard(s),
|
||||
const SizedBox(height: 16),
|
||||
_tripsSection(ctl),
|
||||
const SizedBox(height: 24),
|
||||
_progressSection(),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// قسم التقدّم — ما كان شاشة «الإحصائيات» المنفصلة.
|
||||
///
|
||||
/// في GetBuilder خاصّ به: بيانات التلعيب تصل من نقطة أخرى وفي وقت
|
||||
/// آخر، وربطها بمُنشئ الأرباح كان سيعيد رسم الشاشة كلها — بأرقام
|
||||
/// المال وقوائم الرحلات — كلما تحدّث عدّاد إنجاز.
|
||||
Widget _progressSection() => GetBuilder<GamificationController>(
|
||||
builder: (gc) {
|
||||
if (gc.isLoading) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('تقدّمي', style: FinanceDesignSystem.headingStyle),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// هدف اليوم بعد الأرباح مباشرةً منطقياً — لكنه هنا لأنه
|
||||
// تحفيز لا معلومة: مكانه بعد أن يعرف السائق أرقامه.
|
||||
DailyGoalWidget(controller: gc),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
LevelProgressWidget(controller: gc),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
BehaviorSection(gc: gc),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
AchievementsSection(gc: gc),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Widget _errorState(EarningsController ctl) => Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.cloud_off_rounded,
|
||||
size: 48, color: FinanceDesignSystem.textMuted),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
ctl.errorMessage ?? 'تعذّر تحميل أرباحك',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.primaryDark, fontSize: 15),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'أرباحك محفوظة ولم يضع منها شيء — المشكلة في التحميل فقط.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary, fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => ctl.load(force: true),
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
label: const Text('إعادة المحاولة'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// بيانات قديمة معروضة بعد فشل التحديث. إظهار ذلك صراحةً أصدق من
|
||||
/// تقديم رقمٍ عمره ساعات على أنه لحظته.
|
||||
Widget _staleBanner(EarningsController ctl) => Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.mainRadius),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.history_rounded, color: Colors.orange, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${ctl.errorMessage} — هذه أرقام ${ctl.lastUpdatedLabel}',
|
||||
style: const TextStyle(color: Colors.orange, fontSize: 12),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => ctl.load(force: true),
|
||||
child: const Text('تحديث', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
/// بطاقة اليوم — الرقم الذي فُتحت الشاشة من أجله.
|
||||
Widget _todayCard(EarningsSummary s, EarningsController ctl) {
|
||||
final t = s.today;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: FinanceDesignSystem.balanceGradient,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
boxShadow: [FinanceDesignSystem.softShadow],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('أرباح اليوم',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 13)),
|
||||
const Spacer(),
|
||||
Text(ctl.lastUpdatedLabel,
|
||||
style: const TextStyle(color: Colors.white54, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text('${t.net.toStringAsFixed(2)} ${CurrencyHelper.currency}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 34,
|
||||
fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
_miniStat(Icons.local_taxi_rounded, '${t.trips}', 'رحلة'),
|
||||
_miniStat(Icons.schedule_rounded,
|
||||
t.hours.toStringAsFixed(1), 'ساعة'),
|
||||
_miniStat(Icons.route_rounded,
|
||||
t.distance.toStringAsFixed(0), 'كم'),
|
||||
],
|
||||
),
|
||||
// تركيبة المبلغ ظاهرة: إجمالي ← عمولة ← صافي. السائق الذي يرى
|
||||
// التركيبة يفهم، والذي يرى الصافي وحده يخمّن ويشكّ.
|
||||
if (t.gross > 0) ...[
|
||||
const SizedBox(height: 14),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_breakdownBit('دفع الركاب', t.gross),
|
||||
_breakdownBit('عمولة المنصة', t.commission, dim: true),
|
||||
_breakdownBit('لك', t.net, bold: true),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _miniStat(IconData icon, String value, String label) => Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: Colors.white70, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Text(value,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700)),
|
||||
const SizedBox(width: 3),
|
||||
Text(label,
|
||||
style: const TextStyle(color: Colors.white54, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _breakdownBit(String label, double value,
|
||||
{bool dim = false, bool bold = false}) =>
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.6), fontSize: 10)),
|
||||
const SizedBox(height: 2),
|
||||
Text(value.toStringAsFixed(2),
|
||||
style: TextStyle(
|
||||
color: dim
|
||||
? Colors.white.withValues(alpha: 0.7)
|
||||
: Colors.white,
|
||||
fontSize: bold ? 15 : 13,
|
||||
fontWeight: bold ? FontWeight.bold : FontWeight.w500)),
|
||||
],
|
||||
);
|
||||
|
||||
/// الاقتطاعات بجانب الأرباح التي اقتُطعت منها. عرضها في شاشة المنتج
|
||||
/// وحدها كان سيجعل الخصم مفاجأةً — وهي أخطر ما يصيب منتجاً ائتمانياً.
|
||||
Widget _deductionsCard(Deductions d) => Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.cardColor,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
border: Border.all(color: FinanceDesignSystem.borderColor),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.account_balance_wallet_rounded,
|
||||
size: 18, color: FinanceDesignSystem.accentBlue),
|
||||
const SizedBox(width: 8),
|
||||
Text('الاقتطاعات', style: FinanceDesignSystem.headingStyle),
|
||||
const Spacer(),
|
||||
if (d.today > 0)
|
||||
Text('اليوم ${d.today.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary,
|
||||
fontSize: 12)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
...d.items.map((i) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(i.name,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.primaryDark,
|
||||
fontSize: 13))),
|
||||
Text(
|
||||
'متبقٍّ ${i.outstanding.toStringAsFixed(2)} ${CurrencyHelper.currency}',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary,
|
||||
fontSize: 12)),
|
||||
],
|
||||
),
|
||||
)),
|
||||
if (d.outstanding > 0) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'يُقتطع تدريجياً من أرباحك بسقف يومي، ولا يُخصم منك في يوم بلا دخل.',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary, fontSize: 11),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _weekCard(EarningsSummary s, EarningsController ctl) {
|
||||
final maxNet = s.daily.fold<double>(
|
||||
0, (m, d) => d.net > m ? d.net : m);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.cardColor,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
border: Border.all(color: FinanceDesignSystem.borderColor),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text('آخر ٧ أيام', style: FinanceDesignSystem.headingStyle),
|
||||
const Spacer(),
|
||||
if (s.trendPercent != null) _trendChip(s.trendPercent!),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${s.week.net.toStringAsFixed(2)} ${CurrencyHelper.currency} · ${s.week.trips} رحلة',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary, fontSize: 13)),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 110,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: s.daily.map((d) {
|
||||
final selected = ctl.selectedDay == d.day;
|
||||
final ratio = maxNet > 0 ? d.net / maxNet : 0.0;
|
||||
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
// نقر العمود يعرض رحلات ذلك اليوم. الرسم البياني الذي
|
||||
// لا يُنقر عليه زينة؛ والسائق يسأل عن يومٍ بعينه.
|
||||
onTap: () => ctl.loadTrips(day: selected ? null : d.day),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(d.net > 0 ? d.net.toStringAsFixed(0) : '',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary,
|
||||
fontSize: 9)),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
height: 60 * (ratio == 0 ? 0.03 : ratio),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: selected
|
||||
? FinanceDesignSystem.accentBlue
|
||||
: FinanceDesignSystem.accentBlue
|
||||
.withValues(alpha: 0.35),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(_dayLabel(d.day),
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary,
|
||||
fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// الشهر — يحلّ محل الرسم الشهري في الشاشة القديمة.
|
||||
///
|
||||
/// أرقام لا رسم بياني: الرسم الشهري كان ثلاثين عموداً ضيّقاً لا يُقرأ
|
||||
/// منها شيء على شاشة هاتف. السائق يسأل عن مجموع شهره ومعدّله اليومي،
|
||||
/// لا عن شكل توزيعه.
|
||||
Widget _monthCard(EarningsSummary s) {
|
||||
final m = s.month;
|
||||
final avgPerDay = DateTime.now().day > 0 ? m.net / DateTime.now().day : 0.0;
|
||||
final perHour = m.hours > 0 ? m.net / m.hours : 0.0;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.cardColor,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
border: Border.all(color: FinanceDesignSystem.borderColor),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('هذا الشهر', style: FinanceDesignSystem.headingStyle),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
_monthStat('الصافي', m.net.toStringAsFixed(0)),
|
||||
_monthStat('رحلة', '${m.trips}'),
|
||||
_monthStat('ساعة', m.hours.toStringAsFixed(0)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
// معدّل الساعة هو الرقم الذي يقرّر به السائق متى يعمل —
|
||||
// وأنفع من أي مجموع، لأن المجموع يكافئ الساعات لا الكفاءة.
|
||||
_monthStat('معدّل الساعة', perHour.toStringAsFixed(1)),
|
||||
_monthStat('معدّل اليوم', avgPerDay.toStringAsFixed(1)),
|
||||
_monthStat('العمولة', m.commission.toStringAsFixed(0)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _monthStat(String label, String value) => Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.primaryDark,
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 2),
|
||||
Text(label,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _trendChip(double trend) {
|
||||
final up = trend >= 0;
|
||||
final color =
|
||||
up ? FinanceDesignSystem.successGreen : FinanceDesignSystem.dangerRed;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(up ? Icons.trending_up_rounded : Icons.trending_down_rounded,
|
||||
size: 14, color: color),
|
||||
const SizedBox(width: 4),
|
||||
// المقارنة بأسبوعه هو لا بالسائقين الآخرين.
|
||||
Text('${trend.abs().toStringAsFixed(0)}٪ عن الأسبوع الماضي',
|
||||
style: TextStyle(color: color, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _dayLabel(String iso) {
|
||||
final d = DateTime.tryParse(iso);
|
||||
if (d == null) return '';
|
||||
const names = ['اثن', 'ثلا', 'أرب', 'خمي', 'جمع', 'سبت', 'أحد'];
|
||||
return names[d.weekday - 1];
|
||||
}
|
||||
|
||||
Widget _tripsSection(EarningsController ctl) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
ctl.selectedDay == null
|
||||
? 'رحلات الأسبوع'
|
||||
: 'رحلات ${ctl.selectedDay}',
|
||||
style: FinanceDesignSystem.headingStyle),
|
||||
const Spacer(),
|
||||
if (ctl.selectedDay != null)
|
||||
TextButton(
|
||||
onPressed: () => ctl.loadTrips(),
|
||||
child: const Text('كل الأسبوع',
|
||||
style: TextStyle(fontSize: 12))),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (ctl.isLoadingTrips)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
else if (ctl.trips.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
child: Center(
|
||||
child: Text('لا رحلات في هذه الفترة',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary,
|
||||
fontSize: 13)),
|
||||
),
|
||||
)
|
||||
else
|
||||
...ctl.trips.map(_tripTile),
|
||||
],
|
||||
);
|
||||
|
||||
/// تفصيل الرحلة الواحدة — الإجابة على السؤال الأول عند كل سائق:
|
||||
/// «لماذا أخذت هذا المبلغ من هذه الرحلة؟»
|
||||
Widget _tripTile(TripEarning t) {
|
||||
final b = t.breakdown;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.cardColor,
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.mainRadius),
|
||||
border: Border.all(color: FinanceDesignSystem.borderColor),
|
||||
),
|
||||
child: Theme(
|
||||
data: ThemeData(dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
childrenPadding: const EdgeInsets.fromLTRB(14, 0, 14, 12),
|
||||
title: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${t.from} ← ${t.to}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.primaryDark,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('${b.net.toStringAsFixed(2)} ${CurrencyHelper.currency}',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.successGreen,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14)),
|
||||
],
|
||||
),
|
||||
subtitle: Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'${_timeLabel(t.at)} · ${t.distanceKm.toStringAsFixed(1)} كم · ${t.minutes} د',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary, fontSize: 11),
|
||||
),
|
||||
if (b.zeroCommission) ...[
|
||||
const SizedBox(width: 6),
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.successGreen
|
||||
.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text('عمولة معفاة',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.successGreen,
|
||||
fontSize: 9)),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
children: [
|
||||
_row('ما دفعه الراكب', b.gross),
|
||||
if (b.bonus > 0) _row('مكافأة', b.bonus, positive: true),
|
||||
_row('عمولة المنصة', b.commission, negative: true),
|
||||
Divider(color: FinanceDesignSystem.borderColor, height: 16),
|
||||
_row('صافي لك', b.net, bold: true),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
t.paymentMethod.toLowerCase().contains('cash')
|
||||
? Icons.money_rounded
|
||||
: Icons.credit_card_rounded,
|
||||
size: 13,
|
||||
color: FinanceDesignSystem.textMuted),
|
||||
const SizedBox(width: 5),
|
||||
Text(t.paymentMethod,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textMuted, fontSize: 11)),
|
||||
const Spacer(),
|
||||
Text('#${t.rideId}',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textMuted, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _row(String label, double value,
|
||||
{bool bold = false, bool negative = false, bool positive = false}) =>
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(label,
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.textSecondary,
|
||||
fontSize: bold ? 13 : 12)),
|
||||
),
|
||||
Text(
|
||||
'${negative ? '− ' : positive ? '+ ' : ''}${value.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
color: negative
|
||||
? FinanceDesignSystem.dangerRed
|
||||
: positive
|
||||
? FinanceDesignSystem.successGreen
|
||||
: FinanceDesignSystem.primaryDark,
|
||||
fontSize: bold ? 14 : 12,
|
||||
fontWeight: bold ? FontWeight.bold : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
String _timeLabel(String at) {
|
||||
final d = DateTime.tryParse(at);
|
||||
if (d == null) return '';
|
||||
final h = d.hour.toString().padLeft(2, '0');
|
||||
final m = d.minute.toString().padLeft(2, '0');
|
||||
return '$h:$m';
|
||||
}
|
||||
}
|
||||
@@ -1,522 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_driver/constant/finance_design_system.dart';
|
||||
import 'package:siro_driver/controller/gamification/gamification_controller.dart';
|
||||
import 'package:siro_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) {
|
||||
return GetBuilder<StatisticsController>(
|
||||
builder: (sc) {
|
||||
if (gc.isLoading || sc.isLoading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: FinanceDesignSystem.primaryDark),
|
||||
);
|
||||
}
|
||||
|
||||
return CustomScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
slivers: [
|
||||
// ═══════ App Bar ═══════
|
||||
SliverAppBar(
|
||||
expandedHeight: 200,
|
||||
pinned: true,
|
||||
stretch: true,
|
||||
backgroundColor: Get.isDarkMode
|
||||
? FinanceDesignSystem.primaryDark
|
||||
: const Color(0xFF0A0E21),
|
||||
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(force: true);
|
||||
sc.reloadData(force: true);
|
||||
},
|
||||
),
|
||||
],
|
||||
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: 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: [
|
||||
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: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: FinanceDesignSystem.primaryDark)),
|
||||
Text(title,
|
||||
style: 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: 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,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
// behavior_and_achievements.dart — سلوك القيادة والإنجازات
|
||||
//
|
||||
// نُقلا من `statistics_dashboard.dart` (حيث كانا دالتين خاصّتين) إلى
|
||||
// ودجتين مستقلّتين عند دمج شاشتَي الأرباح والإحصائيات في شاشة واحدة.
|
||||
// نسخهما كان سيعني نسختين تفترقان عند أول تعديل.
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../../constant/finance_design_system.dart';
|
||||
import '../../../../controller/gamification/gamification_controller.dart';
|
||||
|
||||
class BehaviorSection extends StatelessWidget {
|
||||
final GamificationController gc;
|
||||
const BehaviorSection({super.key, required this.gc});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isExcellent = gc.behaviorScore >= 90;
|
||||
final bool isGood = gc.behaviorScore >= 75 && gc.behaviorScore < 90;
|
||||
|
||||
final Color statusColor = isExcellent
|
||||
? Colors.green
|
||||
: isGood
|
||||
? Colors.orange
|
||||
: Colors.red;
|
||||
|
||||
final 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: [
|
||||
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.withValues(alpha: 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: [
|
||||
_statItem(
|
||||
title: 'Score'.tr,
|
||||
value: '${gc.behaviorScore}%',
|
||||
icon: Icons.speed_rounded,
|
||||
color: FinanceDesignSystem.accentBlue,
|
||||
),
|
||||
_statItem(
|
||||
title: 'Max Speed'.tr,
|
||||
value: '${gc.maxSpeed.toStringAsFixed(0)} km/h',
|
||||
icon: Icons.directions_car_rounded,
|
||||
color: Colors.orange,
|
||||
),
|
||||
_statItem(
|
||||
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 _statItem({
|
||||
required String title,
|
||||
required String value,
|
||||
required IconData icon,
|
||||
required Color color,
|
||||
}) =>
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: FinanceDesignSystem.primaryDark)),
|
||||
Text(title,
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: FinanceDesignSystem.textSecondary)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class AchievementsSection extends StatelessWidget {
|
||||
final GamificationController gc;
|
||||
const AchievementsSection({super.key, required this.gc});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final unlocked = gc.achievements.where((a) => a.isUnlocked).toList();
|
||||
final locked = 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.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
'${gc.unlockedCount}/${gc.totalAchievements}',
|
||||
style: TextStyle(
|
||||
color: FinanceDesignSystem.accentBlue,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (unlocked.isNotEmpty) ...[
|
||||
...unlocked.map((a) => _AchievementCard(ach: a, unlocked: true)),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
...locked.map((a) => _AchievementCard(ach: a, unlocked: false)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AchievementCard extends StatelessWidget {
|
||||
final Achievement ach;
|
||||
final bool unlocked;
|
||||
|
||||
const _AchievementCard({required this.ach, required this.unlocked});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isAr = Get.locale?.languageCode == 'ar';
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
// كان اللون هنا Colors.white ثابتاً — يختفي النص عليه في الوضع
|
||||
// الداكن. نستعمل لون البطاقة من نظام التصميم.
|
||||
color: unlocked
|
||||
? FinanceDesignSystem.cardColor
|
||||
: FinanceDesignSystem.cardColor.withValues(alpha: 0.6),
|
||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||
border: unlocked
|
||||
? Border.all(color: ach.color.withValues(alpha: 0.3), width: 1.5)
|
||||
: Border.all(color: FinanceDesignSystem.borderColor),
|
||||
boxShadow: unlocked
|
||||
? [
|
||||
BoxShadow(
|
||||
color: ach.color.withValues(alpha: 0.1),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: unlocked
|
||||
? ach.color.withValues(alpha: 0.15)
|
||||
: FinanceDesignSystem.textMuted.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Icon(
|
||||
ach.icon,
|
||||
color: unlocked ? ach.color : FinanceDesignSystem.textMuted,
|
||||
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
|
||||
: FinanceDesignSystem.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
isAr ? ach.descriptionAr : ach.descriptionEn,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: FinanceDesignSystem.textSecondary),
|
||||
),
|
||||
if (!unlocked) ...[
|
||||
const SizedBox(height: 8),
|
||||
Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: FinanceDesignSystem.textMuted
|
||||
.withValues(alpha: 0.25),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
FractionallySizedBox(
|
||||
widthFactor: ach.progress,
|
||||
child: Container(
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: ach.color.withValues(alpha: 0.6),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${ach.currentProgress}/${ach.target}',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: FinanceDesignSystem.textMuted,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
if (unlocked)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: ach.color.withValues(alpha: 0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(Icons.check_rounded, color: ach.color, size: 18),
|
||||
)
|
||||
else
|
||||
Icon(Icons.lock_outline_rounded,
|
||||
color: FinanceDesignSystem.textMuted, size: 20),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
import 'package:siro_driver/constant/currency.dart';
|
||||
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: FinanceDesignSystem.cardColor,
|
||||
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: 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)} ${CurrencyHelper.currency}',
|
||||
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)} ${CurrencyHelper.currency}',
|
||||
const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
drawVerticalLine: false,
|
||||
getDrawingHorizontalLine: (v) => FlLine(
|
||||
color: FinanceDesignSystem.borderColor,
|
||||
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: FinanceDesignSystem.textSecondary)),
|
||||
),
|
||||
)),
|
||||
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: FinanceDesignSystem.textSecondary),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import 'package:siro_driver/constant/currency.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_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: FinanceDesignSystem.cardColor,
|
||||
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: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: FinanceDesignSystem.primaryDark)),
|
||||
const SizedBox(height: 4),
|
||||
Text('Summary of your daily activity'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 11, color: FinanceDesignSystem.textSecondary)),
|
||||
const SizedBox(height: 20),
|
||||
_buildRow(
|
||||
Icons.monetization_on_rounded,
|
||||
'Earnings'.tr,
|
||||
'${hc.totalMoneyToday} ${CurrencyHelper.currency}',
|
||||
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: FinanceDesignSystem.primaryDark))),
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: FinanceDesignSystem.primaryDark,
|
||||
fontFamily: 'digit')),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
import 'package:siro_driver/constant/currency.dart';
|
||||
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: FinanceDesignSystem.cardColor,
|
||||
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: 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)} ${CurrencyHelper.currency}',
|
||||
style: 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)} ${CurrencyHelper.currency}',
|
||||
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: FinanceDesignSystem
|
||||
.textSecondary)));
|
||||
}
|
||||
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: FinanceDesignSystem.textSecondary)),
|
||||
]);
|
||||
}
|
||||
|
||||
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