Files
TravelMate/lib/models/budget_category.dart
Van Leemput Dayron 9b08b2896c feat: Add services for managing trip-related data
- Implement EmergencyService for handling emergency contacts per trip.
- Create GuestFlagService to manage guest mode flags for trips.
- Introduce NotificationService with local notification capabilities.
- Add OfflineFlagService for managing offline caching flags.
- Develop PackingService for shared packing lists per trip.
- Implement ReminderService for managing reminders/to-dos per trip.
- Create SosService for dispatching SOS events to a backend.
- Add StorageService with album image upload functionality.
- Implement TransportService for managing transport segments per trip.
- Create TripChecklistService for storing and retrieving trip checklists.
- Add TripDocumentService for persisting trip documents metadata.

test: Add unit tests for new services

- Implement tests for AlbumService, BudgetService, EmergencyService, GuestFlagService, PackingService, ReminderService, SosService, TransportService, TripChecklistService, and TripDocumentService.
- Ensure tests cover adding, loading, deleting, and handling corrupted payloads for each service.
2026-03-13 15:02:23 +01:00

107 lines
2.6 KiB
Dart

import 'dart:convert';
/// Represents a budget envelope per category with currency awareness.
class BudgetCategory {
/// Unique identifier of the category entry.
final String id;
/// Category name (hébergement, transport, food, activités...).
final String name;
/// Planned amount.
final double planned;
/// Currency code (ISO 4217) used for the amount.
final String currency;
/// Amount actually spent (to be filled by expenses sync later).
final double spent;
/// Creation timestamp for ordering.
final DateTime createdAt;
/// Creates a budget category entry.
const BudgetCategory({
required this.id,
required this.name,
required this.planned,
required this.currency,
required this.spent,
required this.createdAt,
});
/// Convenience constructor for new envelope.
factory BudgetCategory.newCategory({
required String id,
required String name,
required double planned,
required String currency,
}) {
return BudgetCategory(
id: id,
name: name,
planned: planned,
currency: currency,
spent: 0,
createdAt: DateTime.now().toUtc(),
);
}
/// Returns a copy with updated fields.
BudgetCategory copyWith({
String? id,
String? name,
double? planned,
String? currency,
double? spent,
DateTime? createdAt,
}) {
return BudgetCategory(
id: id ?? this.id,
name: name ?? this.name,
planned: planned ?? this.planned,
currency: currency ?? this.currency,
spent: spent ?? this.spent,
createdAt: createdAt ?? this.createdAt,
);
}
/// JSON serialization.
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'planned': planned,
'currency': currency,
'spent': spent,
'createdAt': createdAt.toIso8601String(),
};
}
/// JSON deserialization.
factory BudgetCategory.fromJson(Map<String, dynamic> json) {
return BudgetCategory(
id: json['id'] as String,
name: json['name'] as String,
planned: (json['planned'] as num).toDouble(),
currency: json['currency'] as String,
spent: (json['spent'] as num).toDouble(),
createdAt: DateTime.parse(json['createdAt'] as String),
);
}
/// Encodes a list to JSON string.
static String encodeList(List<BudgetCategory> categories) {
return json.encode(categories.map((c) => c.toJson()).toList());
}
/// Decodes a list from JSON string.
static List<BudgetCategory> decodeList(String raw) {
final decoded = json.decode(raw) as List<dynamic>;
return decoded
.cast<Map<String, dynamic>>()
.map(BudgetCategory.fromJson)
.toList();
}
}