-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatisticsModel.dart
More file actions
68 lines (59 loc) · 1.96 KB
/
StatisticsModel.dart
File metadata and controls
68 lines (59 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import 'package:task_management_app/core/enum/TaskStatus.dart';
class RecentTaskModel{
final int id;
final String title;
final DateTime updatedAt;
final String? avatar;
final TaskStatus status = TaskStatus.completed;
RecentTaskModel({required this.id, required this.title, required this.updatedAt, required this.avatar});
factory RecentTaskModel.fromJson(Map<String,dynamic> json){
return RecentTaskModel(
id: json['id'],
title: json['title'] ?? '',
updatedAt: DateTime.parse(json['updated_at']),
avatar: json['avatar'],
);
}
}
class TodayStatsModel {
final int total;
final int completed;
TodayStatsModel({
required this.total,
required this.completed,
});
factory TodayStatsModel.fromJson(Map<String, dynamic> json) {
return TodayStatsModel(
total: json['total'] ?? 0,
completed: json['completed'] ?? 0,
);
}
}
class UserStatisticsModel {
final TodayStatsModel today;
final double todayCompletedPercentage;
final int thisWeekTotal;
final double growthPercentage;
final List<RecentTaskModel> recentTasks;
final List<int> dailyCounts;
UserStatisticsModel({
required this.today,
required this.todayCompletedPercentage,
required this.thisWeekTotal,
required this.growthPercentage,
required this.recentTasks,
required this.dailyCounts,
});
factory UserStatisticsModel.fromJson(Map<String, dynamic> json) {
return UserStatisticsModel(
today: TodayStatsModel.fromJson(json['today'] ?? {}),
todayCompletedPercentage: (json['today_completed_percentage'] ?? 0).toDouble(),
thisWeekTotal: json['this_week_total'] ?? 0,
growthPercentage: (json['growth_percentage'] ?? 0).toDouble(),
recentTasks: (json['recent_tasks'] as List<dynamic>?)
?.map((item) => RecentTaskModel.fromJson(item as Map<String, dynamic>))
.toList() ?? [],
dailyCounts: List<int>.from(json['daily_counts'] ?? [0, 0, 0, 0, 0, 0, 0]),
);
}
}