You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.2 KiB
78 lines
2.2 KiB
import 'package:get/get.dart'; |
|
|
|
class Problem { |
|
String? id; |
|
String description; |
|
String location; |
|
List<String> imageUrls; |
|
DateTime createdAt; |
|
bool isUploaded; |
|
String? censorTaskId; |
|
String? bindData; |
|
// 添加可观察的选中状态 |
|
final RxBool isChecked = false.obs; |
|
|
|
Problem({ |
|
this.id, |
|
required this.description, |
|
required this.location, |
|
required this.imageUrls, |
|
required this.createdAt, |
|
this.censorTaskId, |
|
this.bindData, |
|
this.isUploaded = false, |
|
}); |
|
|
|
// copyWith 方法:根据字段和构造函数进行修正 |
|
Problem copyWith({ |
|
String? id, |
|
String? description, |
|
String? location, |
|
List<String>? imageUrls, |
|
DateTime? createdAt, |
|
bool? isUploaded, |
|
String? censorTaskId, |
|
String? bindData, |
|
}) { |
|
return Problem( |
|
id: id ?? this.id, |
|
description: description ?? this.description, |
|
location: location ?? this.location, |
|
imageUrls: imageUrls ?? this.imageUrls, |
|
createdAt: createdAt ?? this.createdAt, |
|
isUploaded: isUploaded ?? this.isUploaded, |
|
censorTaskId: censorTaskId ?? this.censorTaskId, |
|
bindData: bindData ?? this.bindData, |
|
); |
|
} |
|
|
|
// toMap 方法:修正键名,确保与 fromMap 保持一致 |
|
Map<String, dynamic> toMap() { |
|
return { |
|
'id': id, |
|
'description': description, |
|
'location': location, |
|
'imageUrls': imageUrls.join(';;'), // 使用正确的键名 'imageUrls' |
|
'createdAt': createdAt.millisecondsSinceEpoch, |
|
'isUploaded': isUploaded ? 1 : 0, |
|
'censorTaskId': censorTaskId, |
|
'bindData': bindData, // 使用正确的键名 'bindData' |
|
}; |
|
} |
|
|
|
// fromMap 方法:修正键名,确保与 toMap 保持一致 |
|
factory Problem.fromMap(Map<String, dynamic> map) { |
|
return Problem( |
|
id: map['id'], |
|
description: map['description'], |
|
location: map['location'], |
|
imageUrls: (map['imageUrls'] as String).split( |
|
';;', |
|
), // 使用正确的键名 'imageUrls' |
|
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt']), |
|
isUploaded: map['isUploaded'] == 1, |
|
censorTaskId: map['censorTaskId'], |
|
bindData: map['bindData'], // 使用正确的键名 'bindData' |
|
); |
|
} |
|
}
|
|
|