import 'Wallet_model.dart'; class WalletTransaction { final double amount; final String description; final int id; final String paymentMethod; final DateTime timestamp; final String type; final Wallet? wallet; WalletTransaction({ required this.amount, required this.description, required this.id, required this.paymentMethod, required this.timestamp, required this.type, this.wallet, }); factory WalletTransaction.fromJson(Map json) { return WalletTransaction( amount: (json['amount'] ?? 0).toDouble(), description: json['description'] ?? '', id: json['id'] ?? 0, paymentMethod: json['paymentMethod'] ?? '', // Simple fix: Handle null timestamp and use correct key name timestamp: (json['timestamp'] ?? json['timestmp']) != null ? DateTime.fromMillisecondsSinceEpoch( json['timestamp'] ?? json['timestmp']) : DateTime.now(), type: json['type'] ?? '', wallet: json['wallet'] != null ? Wallet.fromJson(json['wallet']) : null, ); } Map toJson() { return { 'amount': amount, 'description': description, 'id': id, 'paymentMethod': paymentMethod, 'timestmp': timestamp.millisecondsSinceEpoch, // Keep the API's typo 'type': type, 'wallet': wallet?.toJson(), }; } }