Blame view

lib/generated/json/base/json_convert_content.dart 5.95 KB
056970d8   Key   feat: api
1
2
3
4
5
6
  // ignore_for_file: non_constant_identifier_names
  // ignore_for_file: camel_case_types
  // ignore_for_file: prefer_single_quotes
  
  // This file is automatically generated. DO NOT EDIT, all your changes would be lost.
  import 'package:flutter/material.dart' show debugPrint;
8988aa69   liangchengyou   feat:首页+课程列表数据获取
7
  import 'package:wow_english/models/course_entity.dart';
bcd47f52   Key   fixed: 接口list范型支持
8
  import 'package:wow_english/models/course_module_entity.dart';
2eb67dd4   liangchengyou   feat:调整代码
9
10
  import 'package:wow_english/models/course_process_entity.dart';
  import 'package:wow_english/models/follow_read_entity.dart';
993c1a04   liangchengyou   feat:添加数据模型
11
  import 'package:wow_english/models/listen_entity.dart';
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
12
  import 'package:wow_english/models/read_content_entity.dart';
056970d8   Key   feat: api
13
14
15
16
17
18
19
20
  import 'package:wow_english/models/user_entity.dart';
  
  JsonConvert jsonConvert = JsonConvert();
  typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json);
  typedef EnumConvertFunction<T> = T Function(String value);
  
  class JsonConvert {
  	static final Map<String, JsonConvertFunction> convertFuncMap = {
8988aa69   liangchengyou   feat:首页+课程列表数据获取
21
22
  		(CourseEntity).toString(): CourseEntity.fromJson,
  		(CourseCourseLessons).toString(): CourseCourseLessons.fromJson,
bcd47f52   Key   fixed: 接口list范型支持
23
  		(CourseModuleEntity).toString(): CourseModuleEntity.fromJson,
2eb67dd4   liangchengyou   feat:调整代码
24
25
26
27
28
29
  		(CourseProcessEntity).toString(): CourseProcessEntity.fromJson,
  		(CourseProcessReadings).toString(): CourseProcessReadings.fromJson,
  		(CourseProcessTopics).toString(): CourseProcessTopics.fromJson,
  		(CourseProcessTopicsTopicAnswerList).toString(): CourseProcessTopicsTopicAnswerList.fromJson,
  		(CourseProcessVideos).toString(): CourseProcessVideos.fromJson,
  		(FollowReadEntity).toString(): FollowReadEntity.fromJson,
993c1a04   liangchengyou   feat:添加数据模型
30
  		(ListenEntity).toString(): ListenEntity.fromJson,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
31
  		(ReadContentEntity).toString(): ReadContentEntity.fromJson,
056970d8   Key   feat: api
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  		(UserEntity).toString(): UserEntity.fromJson,
  	};
  
    T? convert<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
      if (value == null) {
        return null;
      }
      if (value is T) {
        return value;
      }
      try {
        return _asT<T>(value, enumConvert: enumConvert);
      } catch (e, stackTrace) {
        debugPrint('asT<$T> $e $stackTrace');
        return null;
      }
    }
  
    List<T?>? convertList<T>(List<dynamic>? value, {EnumConvertFunction? enumConvert}) {
      if (value == null) {
        return null;
      }
      try {
        return value.map((dynamic e) => _asT<T>(e,enumConvert: enumConvert)).toList();
      } catch (e, stackTrace) {
        debugPrint('asT<$T> $e $stackTrace');
        return <T>[];
      }
    }
  
  List<T>? convertListNotNull<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
      if (value == null) {
        return null;
      }
      try {
        return (value as List<dynamic>).map((dynamic e) => _asT<T>(e,enumConvert: enumConvert)!).toList();
      } catch (e, stackTrace) {
        debugPrint('asT<$T> $e $stackTrace');
        return <T>[];
      }
    }
  
    T? _asT<T extends Object?>(dynamic value,
        {EnumConvertFunction? enumConvert}) {
      final String type = T.toString();
      final String valueS = value.toString();
      if (enumConvert != null) {
        return enumConvert(valueS) as T;
      } else if (type == "String") {
        return valueS as T;
      } else if (type == "int") {
        final int? intValue = int.tryParse(valueS);
        if (intValue == null) {
          return double.tryParse(valueS)?.toInt() as T?;
        } else {
          return intValue as T;
        }
      } else if (type == "double") {
        return double.parse(valueS) as T;
      } else if (type == "DateTime") {
        return DateTime.parse(valueS) as T;
      } else if (type == "bool") {
        if (valueS == '0' || valueS == '1') {
          return (valueS == '1') as T;
        }
        return (valueS == 'true') as T;
      } else if (type == "Map" || type.startsWith("Map<")) {
        return value as T;
      } else {
        if (convertFuncMap.containsKey(type)) {
          return convertFuncMap[type]!(Map<String, dynamic>.from(value)) as T;
        } else {
          throw UnimplementedError('$type unimplemented');
        }
      }
    }
  
  	//list is returned by type
  	static M? _getListChildType<M>(List<Map<String, dynamic>> data) {
8988aa69   liangchengyou   feat:首页+课程列表数据获取
111
112
113
114
115
116
  		if(<CourseEntity>[] is M){
  			return data.map<CourseEntity>((Map<String, dynamic> e) => CourseEntity.fromJson(e)).toList() as M;
  		}
  		if(<CourseCourseLessons>[] is M){
  			return data.map<CourseCourseLessons>((Map<String, dynamic> e) => CourseCourseLessons.fromJson(e)).toList() as M;
  		}
bcd47f52   Key   fixed: 接口list范型支持
117
118
  		if(<CourseModuleEntity>[] is M){
  			return data.map<CourseModuleEntity>((Map<String, dynamic> e) => CourseModuleEntity.fromJson(e)).toList() as M;
993c1a04   liangchengyou   feat:添加数据模型
119
  		}
2eb67dd4   liangchengyou   feat:调整代码
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  		if(<CourseProcessEntity>[] is M){
  			return data.map<CourseProcessEntity>((Map<String, dynamic> e) => CourseProcessEntity.fromJson(e)).toList() as M;
  		}
  		if(<CourseProcessReadings>[] is M){
  			return data.map<CourseProcessReadings>((Map<String, dynamic> e) => CourseProcessReadings.fromJson(e)).toList() as M;
  		}
  		if(<CourseProcessTopics>[] is M){
  			return data.map<CourseProcessTopics>((Map<String, dynamic> e) => CourseProcessTopics.fromJson(e)).toList() as M;
  		}
  		if(<CourseProcessTopicsTopicAnswerList>[] is M){
  			return data.map<CourseProcessTopicsTopicAnswerList>((Map<String, dynamic> e) => CourseProcessTopicsTopicAnswerList.fromJson(e)).toList() as M;
  		}
  		if(<CourseProcessVideos>[] is M){
  			return data.map<CourseProcessVideos>((Map<String, dynamic> e) => CourseProcessVideos.fromJson(e)).toList() as M;
  		}
  		if(<FollowReadEntity>[] is M){
  			return data.map<FollowReadEntity>((Map<String, dynamic> e) => FollowReadEntity.fromJson(e)).toList() as M;
  		}
993c1a04   liangchengyou   feat:添加数据模型
138
139
140
  		if(<ListenEntity>[] is M){
  			return data.map<ListenEntity>((Map<String, dynamic> e) => ListenEntity.fromJson(e)).toList() as M;
  		}
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
141
142
143
  		if(<ReadContentEntity>[] is M){
  			return data.map<ReadContentEntity>((Map<String, dynamic> e) => ReadContentEntity.fromJson(e)).toList() as M;
  		}
056970d8   Key   feat: api
144
145
146
147
148
  		if(<UserEntity>[] is M){
  			return data.map<UserEntity>((Map<String, dynamic> e) => UserEntity.fromJson(e)).toList() as M;
  		}
  
  		debugPrint("${M.toString()} not found");
8988aa69   liangchengyou   feat:首页+课程列表数据获取
149
  	
056970d8   Key   feat: api
150
151
152
153
154
155
156
157
158
159
  		return null;
  }
  
  	static M? fromJsonAsT<M>(dynamic json) {
  		if (json is List) {
  			return _getListChildType<M>(json.map((e) => e as Map<String, dynamic>).toList());
  		} else {
  			return jsonConvert.convert<M>(json);
  		}
  	}
8988aa69   liangchengyou   feat:首页+课程列表数据获取
160
  }