Update: 2026-08-08 12:58:16
This commit is contained in:
@@ -278,6 +278,13 @@ class AppLink {
|
||||
static String get getDriverDetails =>
|
||||
"$seferCairoServer/ride/driverWallet/getDriverDetails.php";
|
||||
|
||||
// ================= Earnings Endpoints =================
|
||||
// نقطة واحدة لكل أرقام شاشة الأرباح بختم زمني واحد. النداءات الأربعة
|
||||
// السابقة كانت تصل في لحظات مختلفة فتُنتج أرقاماً لا تتفق.
|
||||
static String get getEarningsSummary =>
|
||||
"$endPoint/ride/earnings/summary.php";
|
||||
static String get getEarningsTrips => "$endPoint/ride/earnings/trips.php";
|
||||
|
||||
// ================= Gamification Endpoints =================
|
||||
static String get getWeeklyAggregate =>
|
||||
"$endPoint/ride/gamification/getWeeklyAggregate.php";
|
||||
|
||||
@@ -299,7 +299,7 @@ class HomeCaptainController extends GetxController {
|
||||
void goToWalletFromConnect() {
|
||||
Get.back();
|
||||
Get.back();
|
||||
Get.to(() => WalletCaptainRefactored());
|
||||
Get.to(() => const WalletCaptainRefactored());
|
||||
}
|
||||
|
||||
void changeRideId() {
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
// earnings_controller.dart — مصدر واحد لأرقام شاشة الأرباح
|
||||
//
|
||||
// كانت الأرقام تُبنى من أربعة نداءات مستقلة، فيصل كلٌّ منها في لحظة
|
||||
// مختلفة وتظهر أرقام لا تتفق. هنا نداء واحد بختم زمني واحد.
|
||||
//
|
||||
// والأهم: **الفشل لا يُترجم أصفاراً**. الكود السابق كان عند فشل الشبكة
|
||||
// يولّد سبعة أيام بأصفار ويعرضها كأنها أرباح السائق — وهو يرى دخله وقد
|
||||
// تبخّر. الحالتان هنا منفصلتان: `hasError` غير «كسبتَ صفراً».
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_driver/constant/links.dart';
|
||||
import 'package:siro_driver/controller/functions/crud.dart';
|
||||
import 'package:siro_driver/main.dart';
|
||||
|
||||
import 'earnings_models.dart';
|
||||
|
||||
class EarningsController extends GetxController {
|
||||
EarningsSummary? summary;
|
||||
List<TripEarning> trips = [];
|
||||
|
||||
bool isLoading = false;
|
||||
bool isLoadingTrips = false;
|
||||
|
||||
/// سبب الفشل كنصّ للسائق، أو null. وجوده يعني «لا نعرف أرباحك الآن»
|
||||
/// لا «أرباحك صفر» — والفرق بينهما هو الفرق بين عطلٍ يُحتمل وثقةٍ تُفقد.
|
||||
String? errorMessage;
|
||||
|
||||
/// هل المعروض من الذاكرة المؤقتة؟ الشاشة تُظهر ذلك صراحةً مع وقت
|
||||
/// القياس، فلا يقرأ السائق رقماً عمره ساعات على أنه لحظته.
|
||||
bool isStale = false;
|
||||
|
||||
DateTime? lastFetch;
|
||||
|
||||
/// اليوم المختار لقائمة الرحلات (null = آخر سبعة أيام).
|
||||
String? selectedDay;
|
||||
|
||||
static const _cacheKey = 'earnings_summary_cache';
|
||||
static const _cacheAtKey = 'earnings_summary_cached_at';
|
||||
|
||||
/// دقيقتان لا ثلاث ساعات. الكاش الطويل السابق كان سبب تناقض شاشة
|
||||
/// الأرباح مع شاشة الرصيد؛ ومدة قصيرة تكفي لمنع النداءات المتكررة
|
||||
/// عند التنقّل بين الشاشات بلا أن تُقدّم للسائق ماضياً على أنه حاضر.
|
||||
static const _freshFor = Duration(minutes: 2);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_loadFromCache();
|
||||
load();
|
||||
}
|
||||
|
||||
void _loadFromCache() {
|
||||
try {
|
||||
final raw = box.read(_cacheKey);
|
||||
if (raw == null) return;
|
||||
|
||||
summary = EarningsSummary.fromJson(
|
||||
Map<String, dynamic>.from(jsonDecode(raw)));
|
||||
|
||||
final at = box.read(_cacheAtKey);
|
||||
if (at != null) lastFetch = DateTime.tryParse(at.toString());
|
||||
isStale = true;
|
||||
update();
|
||||
} catch (e) {
|
||||
debugPrint('[Earnings] تعذّرت قراءة الكاش: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> load({bool force = false}) async {
|
||||
if (!force && lastFetch != null && !isStale) {
|
||||
if (DateTime.now().difference(lastFetch!) < _freshFor) return;
|
||||
}
|
||||
|
||||
isLoading = summary == null; // دوّار فقط حين لا يوجد ما يُعرض
|
||||
errorMessage = null;
|
||||
update();
|
||||
|
||||
final res = await CRUD().get(link: AppLink.getEarningsSummary);
|
||||
|
||||
// الرسائل مفصّلة بحسب سبب الفشل: «تحقق من اتصالك» تُصلح بفعل،
|
||||
// و«حدث خطأ» تترك السائق بلا حيلة.
|
||||
if (res == 'no_internet') {
|
||||
_fail('تعذّر الوصول للخادم — تحقّق من اتصالك');
|
||||
return;
|
||||
}
|
||||
if (res == 'token_expired') {
|
||||
_fail('انتهت الجلسة، حاول مجدداً');
|
||||
return;
|
||||
}
|
||||
if (res == 'failure' || res == null) {
|
||||
_fail('تعذّر تحميل أرباحك الآن');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final data = jsonDecode(res);
|
||||
if (data['status'] != 'success' || data['message'] is! Map) {
|
||||
_fail('تعذّر تحميل أرباحك الآن');
|
||||
return;
|
||||
}
|
||||
|
||||
summary = EarningsSummary.fromJson(
|
||||
Map<String, dynamic>.from(data['message']));
|
||||
|
||||
box.write(_cacheKey, jsonEncode(data['message']));
|
||||
box.write(_cacheAtKey, DateTime.now().toIso8601String());
|
||||
|
||||
lastFetch = DateTime.now();
|
||||
isStale = false;
|
||||
errorMessage = null;
|
||||
} catch (e) {
|
||||
debugPrint('[Earnings] تعذّر تحليل الرد: $e');
|
||||
_fail('تعذّر تحميل أرباحك الآن');
|
||||
return;
|
||||
} finally {
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
await loadTrips();
|
||||
}
|
||||
|
||||
/// الفشل يُبقي آخر بيانات معروفة معروضة ومعلَّمة كقديمة، ولا يستبدلها
|
||||
/// بأصفار. رقم قديم صادق أنفع من رقم حاضر كاذب.
|
||||
void _fail(String message) {
|
||||
errorMessage = message;
|
||||
isLoading = false;
|
||||
if (summary != null) isStale = true;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> loadTrips({String? day}) async {
|
||||
selectedDay = day;
|
||||
isLoadingTrips = true;
|
||||
update();
|
||||
|
||||
final res = await CRUD().get(
|
||||
link: AppLink.getEarningsTrips,
|
||||
payload: {
|
||||
if (day != null) 'date': day,
|
||||
if (day == null) 'range': 'week',
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
if (res is String && res != 'failure' && res != 'no_internet' && res != 'token_expired') {
|
||||
final data = jsonDecode(res);
|
||||
if (data['status'] == 'success' && data['message'] is Map) {
|
||||
final list = data['message']['trips'];
|
||||
trips = (list is List)
|
||||
? list
|
||||
.map((t) => TripEarning.fromJson(Map<String, dynamic>.from(t)))
|
||||
.toList()
|
||||
: <TripEarning>[];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('[Earnings] تعذّر تحليل الرحلات: $e');
|
||||
}
|
||||
|
||||
isLoadingTrips = false;
|
||||
update();
|
||||
}
|
||||
|
||||
/// نصّ «آخر تحديث» بصيغة يفهمها السائق بلا حساب.
|
||||
String get lastUpdatedLabel {
|
||||
if (lastFetch == null) return '';
|
||||
final diff = DateTime.now().difference(lastFetch!);
|
||||
if (diff.inMinutes < 1) return 'الآن';
|
||||
if (diff.inMinutes < 60) return 'قبل ${diff.inMinutes} دقيقة';
|
||||
if (diff.inHours < 24) return 'قبل ${diff.inHours} ساعة';
|
||||
return 'قبل ${diff.inDays} يوم';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
// earnings_models.dart — نماذج شاشة الأرباح
|
||||
//
|
||||
// كل الأرقام تصل من نقطة واحدة (`ride/earnings/summary.php`) بختم زمني
|
||||
// واحد، فلا مجال لأن يتناقض رقمان في الشاشة نفسها.
|
||||
|
||||
class PeriodEarnings {
|
||||
final int trips;
|
||||
|
||||
/// صافي السائق — حصته المثبَّتة لحظة عرض السعر، أي ما وُعد به قبل القبول.
|
||||
final double net;
|
||||
|
||||
/// إجمالي ما دفعه الركاب.
|
||||
final double gross;
|
||||
|
||||
/// عمولة المنصة. تُعرض صراحةً لا تُطرح بصمت: السائق الذي يرى تركيبة
|
||||
/// المبلغ يفهم، والذي يرى الصافي وحده يخمّن ويشكّ.
|
||||
final double commission;
|
||||
|
||||
final double distance;
|
||||
final int minutes;
|
||||
|
||||
PeriodEarnings({
|
||||
required this.trips,
|
||||
required this.net,
|
||||
required this.gross,
|
||||
required this.commission,
|
||||
required this.distance,
|
||||
required this.minutes,
|
||||
});
|
||||
|
||||
double get hours => minutes / 60.0;
|
||||
|
||||
factory PeriodEarnings.fromJson(Map<String, dynamic> j) => PeriodEarnings(
|
||||
trips: int.tryParse(j['trips']?.toString() ?? '0') ?? 0,
|
||||
net: double.tryParse(j['net']?.toString() ?? '0') ?? 0,
|
||||
gross: double.tryParse(j['gross']?.toString() ?? '0') ?? 0,
|
||||
commission: double.tryParse(j['commission']?.toString() ?? '0') ?? 0,
|
||||
distance: double.tryParse(j['distance']?.toString() ?? '0') ?? 0,
|
||||
minutes: int.tryParse(j['minutes']?.toString() ?? '0') ?? 0,
|
||||
);
|
||||
|
||||
static PeriodEarnings empty() => PeriodEarnings(
|
||||
trips: 0, net: 0, gross: 0, commission: 0, distance: 0, minutes: 0);
|
||||
}
|
||||
|
||||
class DayEarnings {
|
||||
final String day;
|
||||
final int trips;
|
||||
final double net;
|
||||
final int minutes;
|
||||
|
||||
DayEarnings(
|
||||
{required this.day,
|
||||
required this.trips,
|
||||
required this.net,
|
||||
required this.minutes});
|
||||
|
||||
factory DayEarnings.fromJson(Map<String, dynamic> j) => DayEarnings(
|
||||
day: j['day']?.toString() ?? '',
|
||||
trips: int.tryParse(j['trips']?.toString() ?? '0') ?? 0,
|
||||
net: double.tryParse(j['net']?.toString() ?? '0') ?? 0,
|
||||
minutes: int.tryParse(j['minutes']?.toString() ?? '0') ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
class DeductionItem {
|
||||
final String product;
|
||||
final String name;
|
||||
final double outstanding;
|
||||
|
||||
DeductionItem(
|
||||
{required this.product, required this.name, required this.outstanding});
|
||||
|
||||
factory DeductionItem.fromJson(Map<String, dynamic> j) => DeductionItem(
|
||||
product: j['product']?.toString() ?? '',
|
||||
name: j['name']?.toString() ?? '',
|
||||
outstanding: double.tryParse(j['outstanding']?.toString() ?? '0') ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
/// الاقتطاعات (تأمين، وقود) تُعرض بجانب الأرباح التي اقتُطعت منها.
|
||||
/// اقتطاعٌ لا يظهر في مكانه يُقرأ سرقةً مهما كان مشروعاً.
|
||||
class Deductions {
|
||||
final double today;
|
||||
final double week;
|
||||
final double month;
|
||||
final double outstanding;
|
||||
final List<DeductionItem> items;
|
||||
|
||||
Deductions({
|
||||
required this.today,
|
||||
required this.week,
|
||||
required this.month,
|
||||
required this.outstanding,
|
||||
required this.items,
|
||||
});
|
||||
|
||||
bool get hasAny => today > 0 || outstanding > 0;
|
||||
|
||||
factory Deductions.fromJson(Map<String, dynamic> j) => Deductions(
|
||||
today: double.tryParse(j['today']?.toString() ?? '0') ?? 0,
|
||||
week: double.tryParse(j['week']?.toString() ?? '0') ?? 0,
|
||||
month: double.tryParse(j['month']?.toString() ?? '0') ?? 0,
|
||||
outstanding: double.tryParse(j['outstanding']?.toString() ?? '0') ?? 0,
|
||||
items: (j['items'] is List)
|
||||
? (j['items'] as List)
|
||||
.map((i) => DeductionItem.fromJson(Map<String, dynamic>.from(i)))
|
||||
.toList()
|
||||
: <DeductionItem>[],
|
||||
);
|
||||
}
|
||||
|
||||
class EarningsSummary {
|
||||
final PeriodEarnings today;
|
||||
final PeriodEarnings week;
|
||||
final PeriodEarnings month;
|
||||
final PeriodEarnings prevWeek;
|
||||
|
||||
/// نسبة التغيّر عن الأسبوع الماضي، أو null إن لم يكن هناك ما يُقارَن به.
|
||||
/// المقارنة بالذات لا بالسائقين الآخرين: ترتيبٌ يُحبط أكثر من يحتاج
|
||||
/// التحفيز — فهو من سيقع في أسفله.
|
||||
final double? trendPercent;
|
||||
|
||||
final List<DayEarnings> daily;
|
||||
final DayEarnings? bestDay;
|
||||
final Deductions deductions;
|
||||
final String asOf;
|
||||
|
||||
EarningsSummary({
|
||||
required this.today,
|
||||
required this.week,
|
||||
required this.month,
|
||||
required this.prevWeek,
|
||||
required this.daily,
|
||||
required this.deductions,
|
||||
required this.asOf,
|
||||
this.trendPercent,
|
||||
this.bestDay,
|
||||
});
|
||||
|
||||
factory EarningsSummary.fromJson(Map<String, dynamic> j) => EarningsSummary(
|
||||
today: PeriodEarnings.fromJson(Map<String, dynamic>.from(j['today'] ?? {})),
|
||||
week: PeriodEarnings.fromJson(Map<String, dynamic>.from(j['week'] ?? {})),
|
||||
month: PeriodEarnings.fromJson(Map<String, dynamic>.from(j['month'] ?? {})),
|
||||
prevWeek:
|
||||
PeriodEarnings.fromJson(Map<String, dynamic>.from(j['prev_week'] ?? {})),
|
||||
trendPercent: j['trend_percent'] == null
|
||||
? null
|
||||
: double.tryParse(j['trend_percent'].toString()),
|
||||
daily: (j['daily'] is List)
|
||||
? (j['daily'] as List)
|
||||
.map((d) => DayEarnings.fromJson(Map<String, dynamic>.from(d)))
|
||||
.toList()
|
||||
: <DayEarnings>[],
|
||||
bestDay: j['best_day'] is Map
|
||||
? DayEarnings.fromJson(Map<String, dynamic>.from(j['best_day']))
|
||||
: null,
|
||||
deductions:
|
||||
Deductions.fromJson(Map<String, dynamic>.from(j['deductions'] ?? {})),
|
||||
asOf: j['as_of']?.toString() ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
class TripBreakdown {
|
||||
final double gross;
|
||||
final double commission;
|
||||
final double bonus;
|
||||
final double net;
|
||||
|
||||
/// إعفاء العمولة (سلسلة ٠٪) — هدية تدفع المنصة ثمنها ولم تكن تظهر
|
||||
/// للسائق في أي شاشة. نميّزها لتُعرض مكسباً لا سطراً فارغاً.
|
||||
final bool zeroCommission;
|
||||
|
||||
TripBreakdown({
|
||||
required this.gross,
|
||||
required this.commission,
|
||||
required this.bonus,
|
||||
required this.net,
|
||||
required this.zeroCommission,
|
||||
});
|
||||
|
||||
factory TripBreakdown.fromJson(Map<String, dynamic> j) => TripBreakdown(
|
||||
gross: double.tryParse(j['gross']?.toString() ?? '0') ?? 0,
|
||||
commission: double.tryParse(j['commission']?.toString() ?? '0') ?? 0,
|
||||
bonus: double.tryParse(j['bonus']?.toString() ?? '0') ?? 0,
|
||||
net: double.tryParse(j['net']?.toString() ?? '0') ?? 0,
|
||||
zeroCommission: j['zero_commission'] == true,
|
||||
);
|
||||
}
|
||||
|
||||
class TripEarning {
|
||||
final int rideId;
|
||||
final String at;
|
||||
final String from;
|
||||
final String to;
|
||||
final String carType;
|
||||
final String paymentMethod;
|
||||
final double distanceKm;
|
||||
final int minutes;
|
||||
final TripBreakdown breakdown;
|
||||
|
||||
TripEarning({
|
||||
required this.rideId,
|
||||
required this.at,
|
||||
required this.from,
|
||||
required this.to,
|
||||
required this.carType,
|
||||
required this.paymentMethod,
|
||||
required this.distanceKm,
|
||||
required this.minutes,
|
||||
required this.breakdown,
|
||||
});
|
||||
|
||||
factory TripEarning.fromJson(Map<String, dynamic> j) => TripEarning(
|
||||
rideId: int.tryParse(j['ride_id']?.toString() ?? '0') ?? 0,
|
||||
at: j['at']?.toString() ?? '',
|
||||
from: j['from']?.toString() ?? '',
|
||||
to: j['to']?.toString() ?? '',
|
||||
carType: j['car_type']?.toString() ?? '',
|
||||
paymentMethod: j['payment_method']?.toString() ?? '',
|
||||
distanceKm: double.tryParse(j['distance_km']?.toString() ?? '0') ?? 0,
|
||||
minutes: int.tryParse(j['minutes']?.toString() ?? '0') ?? 0,
|
||||
breakdown:
|
||||
TripBreakdown.fromJson(Map<String, dynamic>.from(j['breakdown'] ?? {})),
|
||||
);
|
||||
}
|
||||
@@ -1,293 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_driver/constant/box_name.dart';
|
||||
import 'package:siro_driver/constant/links.dart';
|
||||
import 'package:siro_driver/controller/functions/crud.dart';
|
||||
import 'package:siro_driver/models/model/driver/rides_summary_model.dart';
|
||||
import '../../../main.dart';
|
||||
|
||||
class StatisticsController extends GetxController {
|
||||
bool isLoading = false;
|
||||
|
||||
// ═══ Weekly Data ═══
|
||||
List<DayStat> weeklyStats = [];
|
||||
double weeklyEarnings = 0;
|
||||
int weeklyTrips = 0;
|
||||
double weeklyHours = 0;
|
||||
|
||||
// ═══ Monthly Data ═══
|
||||
List<MonthlyPriceDriverModel> monthlyEarnings = [];
|
||||
List<MonthlyRideModel> monthlyRides = [];
|
||||
List<MonthlyDataModel> monthlyDuration = [];
|
||||
double monthlyTotalEarnings = 0;
|
||||
int monthlyTotalTrips = 0;
|
||||
double monthlyTotalHours = 0;
|
||||
String bestDay = '--';
|
||||
double bestDayEarnings = 0;
|
||||
|
||||
// ═══ Tab State ═══
|
||||
int selectedTab = 0; // 0=weekly, 1=monthly
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void changeTab(int tab) {
|
||||
selectedTab = tab;
|
||||
update();
|
||||
}
|
||||
|
||||
// ═══════ جلب البيانات الأسبوعية ═══════
|
||||
Future<void> fetchWeeklyData() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
try {
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getWeeklyAggregate,
|
||||
payload: {
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
},
|
||||
);
|
||||
|
||||
if (res != null && res != 'failure') {
|
||||
box.write('stats_weekly_cache', res);
|
||||
var data = jsonDecode(res);
|
||||
if (data['message'] is List) {
|
||||
weeklyStats = (data['message'] as List)
|
||||
.map((e) => DayStat.fromJson(e))
|
||||
.toList();
|
||||
weeklyEarnings = weeklyStats.fold(0, (s, d) => s + d.earnings);
|
||||
weeklyTrips = weeklyStats.fold(0, (s, d) => s + d.trips);
|
||||
weeklyHours = weeklyStats.fold(0, (s, d) => s + d.hours);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ [Stats] Weekly fetch error: $e');
|
||||
// Fallback: generate from local data
|
||||
_generateLocalWeeklyData();
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
// ═══════ جلب البيانات الشهرية ═══════
|
||||
Future<void> fetchMonthlyData() async {
|
||||
try {
|
||||
// 1. أرباح شهرية
|
||||
var earningsRes = await CRUD().getWallet(
|
||||
link: AppLink.getAllPaymentFromRide,
|
||||
payload: {'driverID': box.read(BoxName.driverID).toString()},
|
||||
);
|
||||
if (earningsRes != null && earningsRes != 'failure') {
|
||||
box.write('stats_monthly_earnings_cache', earningsRes);
|
||||
var data = jsonDecode(earningsRes);
|
||||
if (data['message'] is List) {
|
||||
monthlyEarnings = (data['message'] as List)
|
||||
.map((e) => MonthlyPriceDriverModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalEarnings =
|
||||
monthlyEarnings.fold(0, (s, d) => s + d.pricePerDay);
|
||||
|
||||
// أفضل يوم
|
||||
if (monthlyEarnings.isNotEmpty) {
|
||||
var best = monthlyEarnings
|
||||
.reduce((a, b) => a.pricePerDay > b.pricePerDay ? a : b);
|
||||
bestDay = best.day.toString();
|
||||
bestDayEarnings = best.pricePerDay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. رحلات شهرية
|
||||
var ridesRes = await CRUD().get(
|
||||
link: AppLink.getRidesDriverByDay,
|
||||
payload: {'driver_id': box.read(BoxName.driverID).toString()},
|
||||
);
|
||||
if (ridesRes != null && ridesRes != 'failure') {
|
||||
box.write('stats_monthly_rides_cache', ridesRes);
|
||||
var data = jsonDecode(ridesRes);
|
||||
if (data['message'] is List) {
|
||||
monthlyRides = (data['message'] as List)
|
||||
.map((e) => MonthlyRideModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalTrips = monthlyRides.fold(0, (s, d) => s + d.countRide);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. ساعات شهرية
|
||||
var durationRes = await CRUD().get(
|
||||
link: AppLink.getTotalDriverDuration,
|
||||
payload: {'driver_id': box.read(BoxName.driverID).toString()},
|
||||
);
|
||||
if (durationRes != null && durationRes != 'failure') {
|
||||
box.write('stats_monthly_duration_cache', durationRes);
|
||||
var data = jsonDecode(durationRes);
|
||||
if (data['message'] is List) {
|
||||
monthlyDuration = (data['message'] as List)
|
||||
.map((e) => MonthlyDataModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalHours =
|
||||
monthlyDuration.fold(0, (s, d) => s + d.totalDuration.toDouble());
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ [Stats] Monthly fetch error: $e');
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void _generateLocalWeeklyData() {
|
||||
// Fallback بيانات محلية عند عدم توفر الـ API
|
||||
final now = DateTime.now();
|
||||
weeklyStats = List.generate(7, (i) {
|
||||
final day = now.subtract(Duration(days: 6 - i));
|
||||
return DayStat(
|
||||
date: day,
|
||||
dayName: _getDayName(day.weekday),
|
||||
earnings: 0,
|
||||
trips: 0,
|
||||
hours: 0,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
String _getDayName(int weekday) {
|
||||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
return days[weekday - 1];
|
||||
}
|
||||
|
||||
bool _isFetching = false;
|
||||
|
||||
Future<void> reloadData({bool force = false}) async {
|
||||
if (_isFetching) return;
|
||||
_isFetching = true;
|
||||
|
||||
// التحقق من التخزين المؤقت (3 ساعات)
|
||||
String? lastFetchStr = box.read('stats_last_fetch');
|
||||
if (!force && lastFetchStr != null) {
|
||||
try {
|
||||
DateTime lastFetch = DateTime.parse(lastFetchStr);
|
||||
if (DateTime.now().difference(lastFetch).inHours < 3) {
|
||||
debugPrint('ℹ️ [Statistics] Loading cached statistics (last fetch: $lastFetchStr)');
|
||||
|
||||
// تحميل الكاش الأسبوعي
|
||||
String? weeklyCache = box.read('stats_weekly_cache');
|
||||
if (weeklyCache != null) {
|
||||
var data = jsonDecode(weeklyCache);
|
||||
if (data['message'] is List) {
|
||||
weeklyStats = (data['message'] as List)
|
||||
.map((e) => DayStat.fromJson(e))
|
||||
.toList();
|
||||
weeklyEarnings = weeklyStats.fold(0, (s, d) => s + d.earnings);
|
||||
weeklyTrips = weeklyStats.fold(0, (s, d) => s + d.trips);
|
||||
weeklyHours = weeklyStats.fold(0, (s, d) => s + d.hours);
|
||||
}
|
||||
}
|
||||
|
||||
// تحميل الكاش الشهري (الأرباح)
|
||||
String? earningsCache = box.read('stats_monthly_earnings_cache');
|
||||
if (earningsCache != null) {
|
||||
var data = jsonDecode(earningsCache);
|
||||
if (data['message'] is List) {
|
||||
monthlyEarnings = (data['message'] as List)
|
||||
.map((e) => MonthlyPriceDriverModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalEarnings =
|
||||
monthlyEarnings.fold(0, (s, d) => s + d.pricePerDay);
|
||||
if (monthlyEarnings.isNotEmpty) {
|
||||
var best = monthlyEarnings
|
||||
.reduce((a, b) => a.pricePerDay > b.pricePerDay ? a : b);
|
||||
bestDay = best.day.toString();
|
||||
bestDayEarnings = best.pricePerDay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// تحميل الكاش الشهري (الرحلات)
|
||||
String? ridesCache = box.read('stats_monthly_rides_cache');
|
||||
if (ridesCache != null) {
|
||||
var data = jsonDecode(ridesCache);
|
||||
if (data['message'] is List) {
|
||||
monthlyRides = (data['message'] as List)
|
||||
.map((e) => MonthlyRideModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalTrips = monthlyRides.fold(0, (s, d) => s + d.countRide);
|
||||
}
|
||||
}
|
||||
|
||||
// تحميل الكاش الشهري (المدد)
|
||||
String? durationCache = box.read('stats_monthly_duration_cache');
|
||||
if (durationCache != null) {
|
||||
var data = jsonDecode(durationCache);
|
||||
if (data['message'] is List) {
|
||||
monthlyDuration = (data['message'] as List)
|
||||
.map((e) => MonthlyDataModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalHours =
|
||||
monthlyDuration.fold(0, (s, d) => s + d.totalDuration.toDouble());
|
||||
}
|
||||
}
|
||||
|
||||
_isFetching = false;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('⚠️ [Statistics] Failed to load cached statistics: $e');
|
||||
}
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
try {
|
||||
debugPrint('📊 [Statistics] Reloading data from server...');
|
||||
await fetchWeeklyData();
|
||||
await fetchMonthlyData();
|
||||
box.write('stats_last_fetch', DateTime.now().toIso8601String());
|
||||
debugPrint('📊 [Statistics] Data reload complete.');
|
||||
} catch (e) {
|
||||
debugPrint('❌ [Statistics] Error reloading data: $e');
|
||||
} finally {
|
||||
_isFetching = false;
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════ نموذج إحصائية اليوم ═══════
|
||||
class DayStat {
|
||||
final DateTime date;
|
||||
final String dayName;
|
||||
final double earnings;
|
||||
final int trips;
|
||||
final double hours;
|
||||
|
||||
DayStat({
|
||||
required this.date,
|
||||
required this.dayName,
|
||||
required this.earnings,
|
||||
required this.trips,
|
||||
required this.hours,
|
||||
});
|
||||
|
||||
factory DayStat.fromJson(Map<String, dynamic> json) {
|
||||
final date =
|
||||
DateTime.tryParse(json['day']?.toString() ?? '') ?? DateTime.now();
|
||||
const dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
return DayStat(
|
||||
date: date,
|
||||
dayName: dayNames[date.weekday - 1],
|
||||
earnings: double.tryParse(json['earnings']?.toString() ?? '0') ?? 0,
|
||||
trips: int.tryParse(json['trips']?.toString() ?? '0') ?? 0,
|
||||
hours: double.tryParse(json['hours']?.toString() ?? '0') ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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