Blame view

lib/models/course_module_entity.dart 1.9 KB
993c1a04   liangchengyou   feat:添加数据模型
1
2
  import 'dart:convert';
  
bcd47f52   Key   fixed: 接口list范型支持
3
4
5
  import 'package:wow_english/generated/json/base/json_field.dart';
  import 'package:wow_english/generated/json/course_module_entity.g.dart';
  
993c1a04   liangchengyou   feat:添加数据模型
6
  @JsonSerializable()
bcd47f52   Key   fixed: 接口list范型支持
7
  class CourseModuleEntity {
2187c85f   吴启风   feat:课程结构调整
8
    int? id;
bcd47f52   Key   fixed: 接口list范型支持
9
10
11
12
13
14
15
16
17
18
19
20
21
    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;
e5c9e98f   liangchengyou   feat:首页模块颜色
22
    String? courseModuleThemeColor;
993c1a04   liangchengyou   feat:添加数据模型
23
  
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
24
25
    // 无参构造函数
    CourseModuleEntity.empty();
993c1a04   liangchengyou   feat:添加数据模型
26
  
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
27
    // 命名构造函数
8ce8acaa   吴启风   feat:修复阶段主题色赋值没生效
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    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,
    });
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
45
46
47
  
    factory CourseModuleEntity.fromJson(Map<String, dynamic> json) =>
        $CourseModuleEntityFromJson(json);
993c1a04   liangchengyou   feat:添加数据模型
48
  
bcd47f52   Key   fixed: 接口list范型支持
49
    Map<String, dynamic> toJson() => $CourseModuleEntityToJson(this);
993c1a04   liangchengyou   feat:添加数据模型
50
  
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
51
52
53
54
55
56
    // 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,
8ce8acaa   吴启风   feat:修复阶段主题色赋值没生效
57
        name: courseModuleName,
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
58
59
60
61
62
        courseModuleThemeColor: courseModuleThemeColor,
        // Set default values or leave other fields null
      );
    }
  
bcd47f52   Key   fixed: 接口list范型支持
63
64
65
66
67
    @override
    String toString() {
      return jsonEncode(this);
    }
  }
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
68
69
70
  
  ///对可空的CourseModuleEntity对象扩展
  extension PersonSafeExt on CourseModuleEntity? {
3f8611be   吴启风   feat:阶段主题白色兜底颜色格式...
71
    ///获取非空的主题色,白色兜底
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
72
    String getSafeThemeColor() {
3f8611be   吴启风   feat:阶段主题白色兜底颜色格式...
73
      return this?.courseModuleThemeColor ?? '#FFFFFFFF';
42f15f6c   吴启风   feat:模块选择持久化&模块主题...
74
75
76
77
78
79
80
    }
  
    ///获取非空的阶段名称
    String getSafeName() {
      return this?.name ?? 'learn wow!';
    }
  }