import 'package:flutter/material.dart'; /// 记账类型枚举 enum RecordType { expense, // 支出 income, // 收入 } /// 记账分类模型 class Category { final String id; final String name; final IconData icon; final RecordType type; final String? parentId; // 为未来二级分类预留 const Category({ required this.id, required this.name, required this.icon, required this.type, this.parentId, }); } /// 记账记录模型 class Record { final String id; final RecordType type; final String categoryId; final String? note; final double amount; final DateTime createTime; final String? accountId; // 为未来账户功能预留 final List? imageUrls; // 为未来配图功能预留 Record({ required this.id, required this.type, required this.categoryId, this.note, required this.amount, required this.createTime, this.accountId, this.imageUrls, }); // 转换为JSON格式,方便存储 Map toJson() => { 'id': id, 'type': type.index, 'categoryId': categoryId, 'note': note, 'amount': amount, 'createTime': createTime.toIso8601String(), 'accountId': accountId, 'imageUrls': imageUrls, }; // 从JSON格式转换回对象 factory Record.fromJson(Map json) => Record( id: json['id'], type: RecordType.values[json['type']], categoryId: json['categoryId'], note: json['note'], amount: json['amount'], createTime: DateTime.parse(json['createTime']), accountId: json['accountId'], imageUrls: json['imageUrls'] != null ? List.from(json['imageUrls']) : null, ); }