course_module_entity.dart
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'dart:convert';
import 'package:wow_english/generated/json/base/json_field.dart';
import 'package:wow_english/generated/json/course_module_entity.g.dart';
@JsonSerializable()
class CourseModuleEntity {
int? id;
String? code;
int? courseModuleThemeId;
int? courseTotal;
String? coverUrl;
String? createTime;
String? deleted;
String? des;
String? modifyTime;
String? name;
int? opening;
String? picUrl;
int? sortOrder;
int? status;
String? courseModuleThemeColor;
// 无参构造函数
CourseModuleEntity.empty();
// 命名构造函数
CourseModuleEntity({
this.id,
this.code,
this.courseModuleThemeId,
this.courseTotal,
this.coverUrl,
this.createTime,
this.deleted,
this.des,
this.modifyTime,
this.name,
this.opening,
this.picUrl,
this.sortOrder,
this.status,
this.courseModuleThemeColor,
});
factory CourseModuleEntity.fromJson(Map<String, dynamic> json) =>
$CourseModuleEntityFromJson(json);
Map<String, dynamic> toJson() => $CourseModuleEntityToJson(this);
// Factory constructor for creating an instance with only three parameters
factory CourseModuleEntity.of(int? courseModuleId, String? courseModuleCode,
String? courseModuleName, String? courseModuleThemeColor) {
return CourseModuleEntity(
id: courseModuleId,
code: courseModuleCode,
name: courseModuleName,
courseModuleThemeColor: courseModuleThemeColor,
// Set default values or leave other fields null
);
}
@override
String toString() {
return jsonEncode(this);
}
}
///对可空的CourseModuleEntity对象扩展
extension PersonSafeExt on CourseModuleEntity? {
///获取非空的主题色,系统主题色0xFF00B6F1兜底
String getSafeThemeColor() {
return this?.courseModuleThemeColor ?? '0xFFFFFFFF';
}
///获取非空的阶段名称
String getSafeName() {
return this?.name ?? 'learn wow!';
}
}