add new featurs like new stat page
This commit is contained in:
@@ -32,8 +32,7 @@ class StatisticsController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchWeeklyData();
|
||||
fetchMonthlyData();
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void changeTab(int tab) {
|
||||
@@ -89,12 +88,13 @@ class StatisticsController extends GetxController {
|
||||
monthlyEarnings = (data['message'] as List)
|
||||
.map((e) => MonthlyPriceDriverModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalEarnings = monthlyEarnings.fold(0, (s, d) => s + d.pricePerDay);
|
||||
monthlyTotalEarnings =
|
||||
monthlyEarnings.fold(0, (s, d) => s + d.pricePerDay);
|
||||
|
||||
// أفضل يوم
|
||||
if (monthlyEarnings.isNotEmpty) {
|
||||
var best = monthlyEarnings.reduce((a, b) =>
|
||||
a.pricePerDay > b.pricePerDay ? a : b);
|
||||
var best = monthlyEarnings
|
||||
.reduce((a, b) => a.pricePerDay > b.pricePerDay ? a : b);
|
||||
bestDay = best.day.toString();
|
||||
bestDayEarnings = best.pricePerDay;
|
||||
}
|
||||
@@ -127,7 +127,8 @@ class StatisticsController extends GetxController {
|
||||
monthlyDuration = (data['message'] as List)
|
||||
.map((e) => MonthlyDataModel.fromJson(e))
|
||||
.toList();
|
||||
monthlyTotalHours = monthlyDuration.fold(0, (s, d) => s + d.totalDuration.toDouble());
|
||||
monthlyTotalHours =
|
||||
monthlyDuration.fold(0, (s, d) => s + d.totalDuration.toDouble());
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -157,9 +158,26 @@ class StatisticsController extends GetxController {
|
||||
return days[weekday - 1];
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
await fetchWeeklyData();
|
||||
await fetchMonthlyData();
|
||||
bool _isFetching = false;
|
||||
|
||||
Future<void> reloadData() async {
|
||||
if (_isFetching) return;
|
||||
_isFetching = true;
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
try {
|
||||
debugPrint('📊 [Statistics] Reloading data...');
|
||||
await fetchWeeklyData();
|
||||
await fetchMonthlyData();
|
||||
debugPrint('📊 [Statistics] Data reload complete.');
|
||||
} catch (e) {
|
||||
debugPrint('❌ [Statistics] Error reloading data: $e');
|
||||
} finally {
|
||||
_isFetching = false;
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +198,8 @@ class DayStat {
|
||||
});
|
||||
|
||||
factory DayStat.fromJson(Map<String, dynamic> json) {
|
||||
final date = DateTime.tryParse(json['day']?.toString() ?? '') ?? DateTime.now();
|
||||
final date =
|
||||
DateTime.tryParse(json['day']?.toString() ?? '') ?? DateTime.now();
|
||||
const dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
return DayStat(
|
||||
date: date,
|
||||
|
||||
Reference in New Issue
Block a user