import 'package:get/get.dart'; class Problem { String? id; String description; String location; List imagePaths; DateTime createdAt; bool isUploaded; String? boundInfo; // 添加可观察的选中状态 final RxBool isChecked = false.obs; Problem({ this.id, required this.description, required this.location, required this.imagePaths, required this.createdAt, this.isUploaded = false, this.boundInfo, }); // copyWith 方法 Problem copyWith({ String? id, String? description, String? location, List? imagePaths, DateTime? createdAt, bool? isUploaded, String? boundInfo, }) { return Problem( id: id ?? this.id, description: description ?? this.description, location: location ?? this.location, imagePaths: imagePaths ?? this.imagePaths, createdAt: createdAt ?? this.createdAt, isUploaded: isUploaded ?? this.isUploaded, boundInfo: boundInfo ?? this.boundInfo, ); } // 添加 toJson 方法 Map toJson() { return { 'id': id, 'description': description, 'location': location, 'imagePaths': imagePaths, // List 类型可以直接序列化 'createdAt': createdAt.toIso8601String(), 'isUploaded': isUploaded, // bool 类型可以直接序列化 'boundInfo': boundInfo, }; } Map toMap() { return { 'id': id, 'description': description, 'location': location, 'imagePaths': imagePaths.join(';;'), 'createdAt': createdAt.toIso8601String(), 'isUploaded': isUploaded ? 1 : 0, 'boundInfo': boundInfo, }; } factory Problem.fromMap(Map map) { return Problem( id: map['id'], description: map['description'], location: map['location'], imagePaths: (map['imagePaths'] as String).split(';;'), createdAt: DateTime.parse(map['createdAt']), isUploaded: map['isUploaded'] == 1, boundInfo: map['boundInfo'], ); } }