Showing
7 changed files
with
588 additions
and
139 deletions
| ... | @@ -8,6 +8,7 @@ import 'package:Parlando/account/models/upload_avatar_entity.dart'; | ... | @@ -8,6 +8,7 @@ import 'package:Parlando/account/models/upload_avatar_entity.dart'; |
| 8 | import 'package:Parlando/account/models/user_entity.dart'; | 8 | import 'package:Parlando/account/models/user_entity.dart'; |
| 9 | import 'package:Parlando/category/models/category_entity.dart'; | 9 | import 'package:Parlando/category/models/category_entity.dart'; |
| 10 | import 'package:Parlando/category/models/category_item_entity.dart'; | 10 | import 'package:Parlando/category/models/category_item_entity.dart'; |
| 11 | +import 'package:Parlando/home/models/home_entity.dart'; | ||
| 11 | import 'package:Parlando/home/models/setting_entity.dart'; | 12 | import 'package:Parlando/home/models/setting_entity.dart'; |
| 12 | import 'package:Parlando/login/models/auth_entity.dart'; | 13 | import 'package:Parlando/login/models/auth_entity.dart'; |
| 13 | import 'package:Parlando/models/upload_entity.dart'; | 14 | import 'package:Parlando/models/upload_entity.dart'; |
| ... | @@ -19,7 +20,7 @@ JsonConvert jsonConvert = JsonConvert(); | ... | @@ -19,7 +20,7 @@ JsonConvert jsonConvert = JsonConvert(); |
| 19 | typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json); | 20 | typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json); |
| 20 | 21 | ||
| 21 | class JsonConvert { | 22 | class JsonConvert { |
| 22 | - static final Map<String, JsonConvertFunction> _convertFuncMap = { | 23 | + static final Map<String, JsonConvertFunction> _convertFuncMap = { |
| 23 | (UploadAvatarEntity).toString(): UploadAvatarEntity.fromJson, | 24 | (UploadAvatarEntity).toString(): UploadAvatarEntity.fromJson, |
| 24 | (UploadAvatarData).toString(): UploadAvatarData.fromJson, | 25 | (UploadAvatarData).toString(): UploadAvatarData.fromJson, |
| 25 | (UploadAvatarError).toString(): UploadAvatarError.fromJson, | 26 | (UploadAvatarError).toString(): UploadAvatarError.fromJson, |
| ... | @@ -35,6 +36,12 @@ class JsonConvert { | ... | @@ -35,6 +36,12 @@ class JsonConvert { |
| 35 | CategoryDataMetaPagination.fromJson, | 36 | CategoryDataMetaPagination.fromJson, |
| 36 | (CategoryError).toString(): CategoryError.fromJson, | 37 | (CategoryError).toString(): CategoryError.fromJson, |
| 37 | (CategoryItemEntity).toString(): CategoryItemEntity.fromJson, | 38 | (CategoryItemEntity).toString(): CategoryItemEntity.fromJson, |
| 39 | + (HomeEntity).toString(): HomeEntity.fromJson, | ||
| 40 | + (HomeData).toString(): HomeData.fromJson, | ||
| 41 | + (HomeDataData).toString(): HomeDataData.fromJson, | ||
| 42 | + (HomeDataMeta).toString(): HomeDataMeta.fromJson, | ||
| 43 | + (HomeDataMetaPagination).toString(): HomeDataMetaPagination.fromJson, | ||
| 44 | + (HomeError).toString(): HomeError.fromJson, | ||
| 38 | (SettingEntity).toString(): SettingEntity.fromJson, | 45 | (SettingEntity).toString(): SettingEntity.fromJson, |
| 39 | (SettingData).toString(): SettingData.fromJson, | 46 | (SettingData).toString(): SettingData.fromJson, |
| 40 | (SettingDataLoginSetting).toString(): SettingDataLoginSetting.fromJson, | 47 | (SettingDataLoginSetting).toString(): SettingDataLoginSetting.fromJson, |
| ... | @@ -208,6 +215,39 @@ class JsonConvert { | ... | @@ -208,6 +215,39 @@ class JsonConvert { |
| 208 | (Map<String, dynamic> e) => CategoryItemEntity.fromJson(e)) | 215 | (Map<String, dynamic> e) => CategoryItemEntity.fromJson(e)) |
| 209 | .toList() as M; | 216 | .toList() as M; |
| 210 | } | 217 | } |
| 218 | + if (<HomeEntity>[] is M) { | ||
| 219 | + return data | ||
| 220 | + .map<HomeEntity>((Map<String, dynamic> e) => HomeEntity.fromJson(e)) | ||
| 221 | + .toList() as M; | ||
| 222 | + } | ||
| 223 | + if (<HomeData>[] is M) { | ||
| 224 | + return data | ||
| 225 | + .map<HomeData>((Map<String, dynamic> e) => HomeData.fromJson(e)) | ||
| 226 | + .toList() as M; | ||
| 227 | + } | ||
| 228 | + if (<HomeDataData>[] is M) { | ||
| 229 | + return data | ||
| 230 | + .map<HomeDataData>( | ||
| 231 | + (Map<String, dynamic> e) => HomeDataData.fromJson(e)) | ||
| 232 | + .toList() as M; | ||
| 233 | + } | ||
| 234 | + if (<HomeDataMeta>[] is M) { | ||
| 235 | + return data | ||
| 236 | + .map<HomeDataMeta>( | ||
| 237 | + (Map<String, dynamic> e) => HomeDataMeta.fromJson(e)) | ||
| 238 | + .toList() as M; | ||
| 239 | + } | ||
| 240 | + if (<HomeDataMetaPagination>[] is M) { | ||
| 241 | + return data | ||
| 242 | + .map<HomeDataMetaPagination>( | ||
| 243 | + (Map<String, dynamic> e) => HomeDataMetaPagination.fromJson(e)) | ||
| 244 | + .toList() as M; | ||
| 245 | + } | ||
| 246 | + if (<HomeError>[] is M) { | ||
| 247 | + return data | ||
| 248 | + .map<HomeError>((Map<String, dynamic> e) => HomeError.fromJson(e)) | ||
| 249 | + .toList() as M; | ||
| 250 | + } | ||
| 211 | if (<SettingEntity>[] is M) { | 251 | if (<SettingEntity>[] is M) { |
| 212 | return data | 252 | return data |
| 213 | .map<SettingEntity>( | 253 | .map<SettingEntity>( |
| ... | @@ -309,10 +349,11 @@ class JsonConvert { | ... | @@ -309,10 +349,11 @@ class JsonConvert { |
| 309 | } | 349 | } |
| 310 | 350 | ||
| 311 | static M? fromJsonAsT<M>(dynamic json) { | 351 | static M? fromJsonAsT<M>(dynamic json) { |
| 312 | - if (json is List) { | 352 | + if (json is List) { |
| 313 | - return _getListChildType<M>(json.map((e) => e as Map<String, dynamic>).toList()); | 353 | + return _getListChildType<M>( |
| 314 | - } else { | 354 | + json.map((e) => e as Map<String, dynamic>).toList()); |
| 315 | - return jsonConvert.asT<M>(json); | 355 | + } else { |
| 316 | - } | 356 | + return jsonConvert.asT<M>(json); |
| 317 | - } | 357 | + } |
| 358 | + } | ||
| 318 | } | 359 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -237,4 +237,4 @@ CategoryError $CategoryErrorFromJson(Map<String, dynamic> json) { | ... | @@ -237,4 +237,4 @@ CategoryError $CategoryErrorFromJson(Map<String, dynamic> json) { |
| 237 | Map<String, dynamic> $CategoryErrorToJson(CategoryError entity) { | 237 | Map<String, dynamic> $CategoryErrorToJson(CategoryError entity) { |
| 238 | final Map<String, dynamic> data = <String, dynamic>{}; | 238 | final Map<String, dynamic> data = <String, dynamic>{}; |
| 239 | return data; | 239 | return data; |
| 240 | -} | 240 | +} |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
lib/generated/json/home_entity.g.dart
0 → 100644
| 1 | +import 'package:Parlando/generated/json/base/json_convert_content.dart'; | ||
| 2 | +import 'package:Parlando/home/models/home_entity.dart'; | ||
| 3 | + | ||
| 4 | +HomeEntity $HomeEntityFromJson(Map<String, dynamic> json) { | ||
| 5 | + final HomeEntity homeEntity = HomeEntity(); | ||
| 6 | + final String? status = jsonConvert.convert<String>(json['status']); | ||
| 7 | + if (status != null) { | ||
| 8 | + homeEntity.status = status; | ||
| 9 | + } | ||
| 10 | + final int? code = jsonConvert.convert<int>(json['code']); | ||
| 11 | + if (code != null) { | ||
| 12 | + homeEntity.code = code; | ||
| 13 | + } | ||
| 14 | + final String? message = jsonConvert.convert<String>(json['message']); | ||
| 15 | + if (message != null) { | ||
| 16 | + homeEntity.message = message; | ||
| 17 | + } | ||
| 18 | + final HomeData? data = jsonConvert.convert<HomeData>(json['data']); | ||
| 19 | + if (data != null) { | ||
| 20 | + homeEntity.data = data; | ||
| 21 | + } | ||
| 22 | + final HomeError? error = jsonConvert.convert<HomeError>(json['error']); | ||
| 23 | + if (error != null) { | ||
| 24 | + homeEntity.error = error; | ||
| 25 | + } | ||
| 26 | + return homeEntity; | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +Map<String, dynamic> $HomeEntityToJson(HomeEntity entity) { | ||
| 30 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
| 31 | + data['status'] = entity.status; | ||
| 32 | + data['code'] = entity.code; | ||
| 33 | + data['message'] = entity.message; | ||
| 34 | + data['data'] = entity.data?.toJson(); | ||
| 35 | + data['error'] = entity.error?.toJson(); | ||
| 36 | + return data; | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +HomeData $HomeDataFromJson(Map<String, dynamic> json) { | ||
| 40 | + final HomeData homeData = HomeData(); | ||
| 41 | + final List<HomeDataData>? data = | ||
| 42 | + jsonConvert.convertListNotNull<HomeDataData>(json['data']); | ||
| 43 | + if (data != null) { | ||
| 44 | + homeData.data = data; | ||
| 45 | + } | ||
| 46 | + final HomeDataMeta? meta = jsonConvert.convert<HomeDataMeta>(json['meta']); | ||
| 47 | + if (meta != null) { | ||
| 48 | + homeData.meta = meta; | ||
| 49 | + } | ||
| 50 | + return homeData; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +Map<String, dynamic> $HomeDataToJson(HomeData entity) { | ||
| 54 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
| 55 | + data['data'] = entity.data?.map((v) => v.toJson()).toList(); | ||
| 56 | + data['meta'] = entity.meta?.toJson(); | ||
| 57 | + return data; | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +HomeDataData $HomeDataDataFromJson(Map<String, dynamic> json) { | ||
| 61 | + final HomeDataData homeDataData = HomeDataData(); | ||
| 62 | + final int? id = jsonConvert.convert<int>(json['id']); | ||
| 63 | + if (id != null) { | ||
| 64 | + homeDataData.id = id; | ||
| 65 | + } | ||
| 66 | + final String? userId = jsonConvert.convert<String>(json['user_id']); | ||
| 67 | + if (userId != null) { | ||
| 68 | + homeDataData.userId = userId; | ||
| 69 | + } | ||
| 70 | + final String? title = jsonConvert.convert<String>(json['title']); | ||
| 71 | + if (title != null) { | ||
| 72 | + homeDataData.title = title; | ||
| 73 | + } | ||
| 74 | + final String? content = jsonConvert.convert<String>(json['content']); | ||
| 75 | + if (content != null) { | ||
| 76 | + homeDataData.content = content; | ||
| 77 | + } | ||
| 78 | + final String? url = jsonConvert.convert<String>(json['url']); | ||
| 79 | + if (url != null) { | ||
| 80 | + homeDataData.url = url; | ||
| 81 | + } | ||
| 82 | + final String? type = jsonConvert.convert<String>(json['type']); | ||
| 83 | + if (type != null) { | ||
| 84 | + homeDataData.type = type; | ||
| 85 | + } | ||
| 86 | + final String? duration = jsonConvert.convert<String>(json['duration']); | ||
| 87 | + if (duration != null) { | ||
| 88 | + homeDataData.duration = duration; | ||
| 89 | + } | ||
| 90 | + final String? size = jsonConvert.convert<String>(json['size']); | ||
| 91 | + if (size != null) { | ||
| 92 | + homeDataData.size = size; | ||
| 93 | + } | ||
| 94 | + final String? poemId = jsonConvert.convert<String>(json['poem_id']); | ||
| 95 | + if (poemId != null) { | ||
| 96 | + homeDataData.poemId = poemId; | ||
| 97 | + } | ||
| 98 | + final String? tempId = jsonConvert.convert<String>(json['temp_id']); | ||
| 99 | + if (tempId != null) { | ||
| 100 | + homeDataData.tempId = tempId; | ||
| 101 | + } | ||
| 102 | + final String? thumbnail = jsonConvert.convert<String>(json['thumbnail']); | ||
| 103 | + if (thumbnail != null) { | ||
| 104 | + homeDataData.thumbnail = thumbnail; | ||
| 105 | + } | ||
| 106 | + final String? bgm = jsonConvert.convert<String>(json['bgm']); | ||
| 107 | + if (bgm != null) { | ||
| 108 | + homeDataData.bgm = bgm; | ||
| 109 | + } | ||
| 110 | + final String? praise = jsonConvert.convert<String>(json['praise']); | ||
| 111 | + if (praise != null) { | ||
| 112 | + homeDataData.praise = praise; | ||
| 113 | + } | ||
| 114 | + final String? view = jsonConvert.convert<String>(json['view']); | ||
| 115 | + if (view != null) { | ||
| 116 | + homeDataData.view = view; | ||
| 117 | + } | ||
| 118 | + final String? collect = jsonConvert.convert<String>(json['collect']); | ||
| 119 | + if (collect != null) { | ||
| 120 | + homeDataData.collect = collect; | ||
| 121 | + } | ||
| 122 | + final String? share = jsonConvert.convert<String>(json['share']); | ||
| 123 | + if (share != null) { | ||
| 124 | + homeDataData.share = share; | ||
| 125 | + } | ||
| 126 | + final String? comment = jsonConvert.convert<String>(json['comment']); | ||
| 127 | + if (comment != null) { | ||
| 128 | + homeDataData.comment = comment; | ||
| 129 | + } | ||
| 130 | + final String? state = jsonConvert.convert<String>(json['state']); | ||
| 131 | + if (state != null) { | ||
| 132 | + homeDataData.state = state; | ||
| 133 | + } | ||
| 134 | + final String? isPublish = jsonConvert.convert<String>(json['is_publish']); | ||
| 135 | + if (isPublish != null) { | ||
| 136 | + homeDataData.isPublish = isPublish; | ||
| 137 | + } | ||
| 138 | + final String? isCheck = jsonConvert.convert<String>(json['is_check']); | ||
| 139 | + if (isCheck != null) { | ||
| 140 | + homeDataData.isCheck = isCheck; | ||
| 141 | + } | ||
| 142 | + final String? createdAt = jsonConvert.convert<String>(json['created_at']); | ||
| 143 | + if (createdAt != null) { | ||
| 144 | + homeDataData.createdAt = createdAt; | ||
| 145 | + } | ||
| 146 | + final String? updatedAt = jsonConvert.convert<String>(json['updated_at']); | ||
| 147 | + if (updatedAt != null) { | ||
| 148 | + homeDataData.updatedAt = updatedAt; | ||
| 149 | + } | ||
| 150 | + return homeDataData; | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +Map<String, dynamic> $HomeDataDataToJson(HomeDataData entity) { | ||
| 154 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
| 155 | + data['id'] = entity.id; | ||
| 156 | + data['user_id'] = entity.userId; | ||
| 157 | + data['title'] = entity.title; | ||
| 158 | + data['content'] = entity.content; | ||
| 159 | + data['url'] = entity.url; | ||
| 160 | + data['type'] = entity.type; | ||
| 161 | + data['duration'] = entity.duration; | ||
| 162 | + data['size'] = entity.size; | ||
| 163 | + data['poem_id'] = entity.poemId; | ||
| 164 | + data['temp_id'] = entity.tempId; | ||
| 165 | + data['thumbnail'] = entity.thumbnail; | ||
| 166 | + data['bgm'] = entity.bgm; | ||
| 167 | + data['praise'] = entity.praise; | ||
| 168 | + data['view'] = entity.view; | ||
| 169 | + data['collect'] = entity.collect; | ||
| 170 | + data['share'] = entity.share; | ||
| 171 | + data['comment'] = entity.comment; | ||
| 172 | + data['state'] = entity.state; | ||
| 173 | + data['is_publish'] = entity.isPublish; | ||
| 174 | + data['is_check'] = entity.isCheck; | ||
| 175 | + data['created_at'] = entity.createdAt; | ||
| 176 | + data['updated_at'] = entity.updatedAt; | ||
| 177 | + return data; | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +HomeDataMeta $HomeDataMetaFromJson(Map<String, dynamic> json) { | ||
| 181 | + final HomeDataMeta homeDataMeta = HomeDataMeta(); | ||
| 182 | + final HomeDataMetaPagination? pagination = | ||
| 183 | + jsonConvert.convert<HomeDataMetaPagination>(json['pagination']); | ||
| 184 | + if (pagination != null) { | ||
| 185 | + homeDataMeta.pagination = pagination; | ||
| 186 | + } | ||
| 187 | + return homeDataMeta; | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +Map<String, dynamic> $HomeDataMetaToJson(HomeDataMeta entity) { | ||
| 191 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
| 192 | + data['pagination'] = entity.pagination?.toJson(); | ||
| 193 | + return data; | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +HomeDataMetaPagination $HomeDataMetaPaginationFromJson( | ||
| 197 | + Map<String, dynamic> json) { | ||
| 198 | + final HomeDataMetaPagination homeDataMetaPagination = | ||
| 199 | + HomeDataMetaPagination(); | ||
| 200 | + final int? total = jsonConvert.convert<int>(json['total']); | ||
| 201 | + if (total != null) { | ||
| 202 | + homeDataMetaPagination.total = total; | ||
| 203 | + } | ||
| 204 | + final int? count = jsonConvert.convert<int>(json['count']); | ||
| 205 | + if (count != null) { | ||
| 206 | + homeDataMetaPagination.count = count; | ||
| 207 | + } | ||
| 208 | + final int? perPage = jsonConvert.convert<int>(json['per_page']); | ||
| 209 | + if (perPage != null) { | ||
| 210 | + homeDataMetaPagination.perPage = perPage; | ||
| 211 | + } | ||
| 212 | + final int? currentPage = jsonConvert.convert<int>(json['current_page']); | ||
| 213 | + if (currentPage != null) { | ||
| 214 | + homeDataMetaPagination.currentPage = currentPage; | ||
| 215 | + } | ||
| 216 | + return homeDataMetaPagination; | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +Map<String, dynamic> $HomeDataMetaPaginationToJson( | ||
| 220 | + HomeDataMetaPagination entity) { | ||
| 221 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
| 222 | + data['total'] = entity.total; | ||
| 223 | + data['count'] = entity.count; | ||
| 224 | + data['per_page'] = entity.perPage; | ||
| 225 | + data['current_page'] = entity.currentPage; | ||
| 226 | + return data; | ||
| 227 | +} | ||
| 228 | + | ||
| 229 | +HomeError $HomeErrorFromJson(Map<String, dynamic> json) { | ||
| 230 | + final HomeError homeError = HomeError(); | ||
| 231 | + return homeError; | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +Map<String, dynamic> $HomeErrorToJson(HomeError entity) { | ||
| 235 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
| 236 | + return data; | ||
| 237 | +} |
lib/home/models/home_entity.dart
0 → 100644
| 1 | +import 'dart:convert'; | ||
| 2 | +import 'package:Parlando/generated/json/base/json_field.dart'; | ||
| 3 | +import 'package:Parlando/generated/json/home_entity.g.dart'; | ||
| 4 | + | ||
| 5 | +@JsonSerializable() | ||
| 6 | +class HomeEntity { | ||
| 7 | + String? status; | ||
| 8 | + int? code; | ||
| 9 | + String? message; | ||
| 10 | + HomeData? data; | ||
| 11 | + HomeError? error; | ||
| 12 | + | ||
| 13 | + HomeEntity(); | ||
| 14 | + | ||
| 15 | + factory HomeEntity.fromJson(Map<String, dynamic> json) => | ||
| 16 | + $HomeEntityFromJson(json); | ||
| 17 | + | ||
| 18 | + Map<String, dynamic> toJson() => $HomeEntityToJson(this); | ||
| 19 | + | ||
| 20 | + @override | ||
| 21 | + String toString() { | ||
| 22 | + return jsonEncode(this); | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +@JsonSerializable() | ||
| 27 | +class HomeData { | ||
| 28 | + List<HomeDataData>? data; | ||
| 29 | + HomeDataMeta? meta; | ||
| 30 | + | ||
| 31 | + HomeData(); | ||
| 32 | + | ||
| 33 | + factory HomeData.fromJson(Map<String, dynamic> json) => | ||
| 34 | + $HomeDataFromJson(json); | ||
| 35 | + | ||
| 36 | + Map<String, dynamic> toJson() => $HomeDataToJson(this); | ||
| 37 | + | ||
| 38 | + @override | ||
| 39 | + String toString() { | ||
| 40 | + return jsonEncode(this); | ||
| 41 | + } | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +@JsonSerializable() | ||
| 45 | +class HomeDataData { | ||
| 46 | + int? id; | ||
| 47 | + @JSONField(name: "user_id") | ||
| 48 | + String? userId; | ||
| 49 | + String? title; | ||
| 50 | + String? content; | ||
| 51 | + String? url; | ||
| 52 | + String? type; | ||
| 53 | + String? duration; | ||
| 54 | + String? size; | ||
| 55 | + @JSONField(name: "poem_id") | ||
| 56 | + String? poemId; | ||
| 57 | + @JSONField(name: "temp_id") | ||
| 58 | + String? tempId; | ||
| 59 | + String? thumbnail; | ||
| 60 | + String? bgm; | ||
| 61 | + String? praise; | ||
| 62 | + String? view; | ||
| 63 | + String? collect; | ||
| 64 | + String? share; | ||
| 65 | + String? comment; | ||
| 66 | + String? state; | ||
| 67 | + @JSONField(name: "is_publish") | ||
| 68 | + String? isPublish; | ||
| 69 | + @JSONField(name: "is_check") | ||
| 70 | + String? isCheck; | ||
| 71 | + @JSONField(name: "created_at") | ||
| 72 | + String? createdAt; | ||
| 73 | + @JSONField(name: "updated_at") | ||
| 74 | + String? updatedAt; | ||
| 75 | + | ||
| 76 | + HomeDataData(); | ||
| 77 | + | ||
| 78 | + factory HomeDataData.fromJson(Map<String, dynamic> json) => | ||
| 79 | + $HomeDataDataFromJson(json); | ||
| 80 | + | ||
| 81 | + Map<String, dynamic> toJson() => $HomeDataDataToJson(this); | ||
| 82 | + | ||
| 83 | + @override | ||
| 84 | + String toString() { | ||
| 85 | + return jsonEncode(this); | ||
| 86 | + } | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +@JsonSerializable() | ||
| 90 | +class HomeDataMeta { | ||
| 91 | + HomeDataMetaPagination? pagination; | ||
| 92 | + | ||
| 93 | + HomeDataMeta(); | ||
| 94 | + | ||
| 95 | + factory HomeDataMeta.fromJson(Map<String, dynamic> json) => | ||
| 96 | + $HomeDataMetaFromJson(json); | ||
| 97 | + | ||
| 98 | + Map<String, dynamic> toJson() => $HomeDataMetaToJson(this); | ||
| 99 | + | ||
| 100 | + @override | ||
| 101 | + String toString() { | ||
| 102 | + return jsonEncode(this); | ||
| 103 | + } | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +@JsonSerializable() | ||
| 107 | +class HomeDataMetaPagination { | ||
| 108 | + int? total; | ||
| 109 | + int? count; | ||
| 110 | + @JSONField(name: "per_page") | ||
| 111 | + int? perPage; | ||
| 112 | + @JSONField(name: "current_page") | ||
| 113 | + int? currentPage; | ||
| 114 | + | ||
| 115 | + HomeDataMetaPagination(); | ||
| 116 | + | ||
| 117 | + factory HomeDataMetaPagination.fromJson(Map<String, dynamic> json) => | ||
| 118 | + $HomeDataMetaPaginationFromJson(json); | ||
| 119 | + | ||
| 120 | + Map<String, dynamic> toJson() => $HomeDataMetaPaginationToJson(this); | ||
| 121 | + | ||
| 122 | + @override | ||
| 123 | + String toString() { | ||
| 124 | + return jsonEncode(this); | ||
| 125 | + } | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +@JsonSerializable() | ||
| 129 | +class HomeError { | ||
| 130 | + HomeError(); | ||
| 131 | + | ||
| 132 | + factory HomeError.fromJson(Map<String, dynamic> json) => | ||
| 133 | + $HomeErrorFromJson(json); | ||
| 134 | + | ||
| 135 | + Map<String, dynamic> toJson() => $HomeErrorToJson(this); | ||
| 136 | + | ||
| 137 | + @override | ||
| 138 | + String toString() { | ||
| 139 | + return jsonEncode(this); | ||
| 140 | + } | ||
| 141 | +} |
| ... | @@ -273,8 +273,8 @@ class _LoginPageState extends State<LoginPage> | ... | @@ -273,8 +273,8 @@ class _LoginPageState extends State<LoginPage> |
| 273 | AppleIDAuthorizationScopes.fullName, | 273 | AppleIDAuthorizationScopes.fullName, |
| 274 | ], | 274 | ], |
| 275 | ); | 275 | ); |
| 276 | - print("authorizationCode:" + credential.authorizationCode); | 276 | + print("authorizationCode:${credential.authorizationCode}"); |
| 277 | - print("identityToken:" + credential.identityToken.toString()); | 277 | + print("identityToken:${credential.identityToken}"); |
| 278 | }, | 278 | }, |
| 279 | ), | 279 | ), |
| 280 | ) | 280 | ) | ... | ... |
| ... | @@ -9,6 +9,7 @@ class HttpApi { | ... | @@ -9,6 +9,7 @@ class HttpApi { |
| 9 | static const String immersive = 'immersive'; | 9 | static const String immersive = 'immersive'; |
| 10 | static const String avatar = 'avatar'; | 10 | static const String avatar = 'avatar'; |
| 11 | static const String user = 'user'; | 11 | static const String user = 'user'; |
| 12 | + static const String home = 'home'; | ||
| 12 | static const String search = 'search/repositories'; | 13 | static const String search = 'search/repositories'; |
| 13 | static const String subscriptions = 'users/simplezhli/subscriptions'; | 14 | static const String subscriptions = 'users/simplezhli/subscriptions'; |
| 14 | static const String upload = 'uuc/upload-inco'; | 15 | static const String upload = 'uuc/upload-inco'; | ... | ... |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | 2 | ||
| 3 | import 'package:Parlando/events/trans_event.dart'; | 3 | import 'package:Parlando/events/trans_event.dart'; |
| 4 | +import 'package:Parlando/home/models/home_entity.dart'; | ||
| 5 | +import 'package:Parlando/net/dio_utils.dart'; | ||
| 6 | +import 'package:Parlando/net/http_api.dart'; | ||
| 7 | +import 'package:Parlando/util/toast_utils.dart'; | ||
| 4 | import 'package:flutter/material.dart'; | 8 | import 'package:flutter/material.dart'; |
| 5 | import 'package:Parlando/category/category_router.dart'; | 9 | import 'package:Parlando/category/category_router.dart'; |
| 6 | import 'package:Parlando/poem/poem_router.dart'; | 10 | import 'package:Parlando/poem/poem_router.dart'; |
| ... | @@ -16,6 +20,7 @@ import 'package:Parlando/tiktok/widgets/tiktok_video_button_column.dart'; | ... | @@ -16,6 +20,7 @@ import 'package:Parlando/tiktok/widgets/tiktok_video_button_column.dart'; |
| 16 | import 'package:Parlando/tiktok/widgets/tiktok_video_poem.dart'; | 20 | import 'package:Parlando/tiktok/widgets/tiktok_video_poem.dart'; |
| 17 | import 'package:Parlando/widgets/bars/home_types_bar.dart'; | 21 | import 'package:Parlando/widgets/bars/home_types_bar.dart'; |
| 18 | import 'package:Parlando/widgets/my_app_bar.dart'; | 22 | import 'package:Parlando/widgets/my_app_bar.dart'; |
| 23 | +import 'package:getwidget/getwidget.dart'; | ||
| 19 | import 'package:video_player/video_player.dart'; | 24 | import 'package:video_player/video_player.dart'; |
| 20 | 25 | ||
| 21 | import 'poem_detail.dart'; | 26 | import 'poem_detail.dart'; |
| ... | @@ -31,13 +36,12 @@ class PoemPage extends StatefulWidget { | ... | @@ -31,13 +36,12 @@ class PoemPage extends StatefulWidget { |
| 31 | 36 | ||
| 32 | class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | 37 | class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
| 33 | TikTokScaffoldController tkController = TikTokScaffoldController(); | 38 | TikTokScaffoldController tkController = TikTokScaffoldController(); |
| 34 | - | ||
| 35 | final PageController _pageController = PageController(); | 39 | final PageController _pageController = PageController(); |
| 36 | - | ||
| 37 | final TikTokVideoListController _videoListController = | 40 | final TikTokVideoListController _videoListController = |
| 38 | TikTokVideoListController(); | 41 | TikTokVideoListController(); |
| 39 | List<UserVideo> videoDataList = []; | 42 | List<UserVideo> videoDataList = []; |
| 40 | late StreamSubscription bus; | 43 | late StreamSubscription bus; |
| 44 | + bool isLoading = false; | ||
| 41 | 45 | ||
| 42 | @override | 46 | @override |
| 43 | void didChangeAppLifecycleState(AppLifecycleState state) async { | 47 | void didChangeAppLifecycleState(AppLifecycleState state) async { |
| ... | @@ -56,46 +60,69 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -56,46 +60,69 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
| 56 | 60 | ||
| 57 | @override | 61 | @override |
| 58 | void initState() { | 62 | void initState() { |
| 59 | - videoDataList = UserVideo.fetchVideo(); | ||
| 60 | WidgetsBinding.instance.addObserver(this); | 63 | WidgetsBinding.instance.addObserver(this); |
| 61 | - _videoListController.init( | 64 | + isLoading = true; |
| 62 | - pageController: _pageController, | 65 | + DioUtils.instance.asyncRequestNetwork<HomeEntity>( |
| 63 | - initialList: videoDataList | 66 | + Method.get, |
| 64 | - .map( | 67 | + HttpApi.home, |
| 65 | - (e) => VPVideoController( | 68 | + params: [], |
| 66 | - videoInfo: e, | 69 | + onSuccess: (data) { |
| 67 | - builder: () => VideoPlayerController.asset(e.url), | 70 | + isLoading = false; |
| 71 | + setState(() {}); | ||
| 72 | + List<UserVideo> videoDataList = <UserVideo>[]; | ||
| 73 | + for (HomeDataData data in data!.data!.data!) { | ||
| 74 | + videoDataList.add( | ||
| 75 | + UserVideo( | ||
| 76 | + image: '', | ||
| 77 | + url: data.url!, | ||
| 78 | + desc: data.content, | ||
| 68 | ), | 79 | ), |
| 69 | - ) | 80 | + ); |
| 70 | - .toList(), | ||
| 71 | - videoProvider: (int index, List<VPVideoController> list) async { | ||
| 72 | - return videoDataList | ||
| 73 | - .map( | ||
| 74 | - (e) => VPVideoController( | ||
| 75 | - videoInfo: e, | ||
| 76 | - builder: () => VideoPlayerController.asset(e.url), | ||
| 77 | - ), | ||
| 78 | - ) | ||
| 79 | - .toList(); | ||
| 80 | - }, | ||
| 81 | - ); | ||
| 82 | - _videoListController.addListener(() { | ||
| 83 | - setState(() {}); | ||
| 84 | - }); | ||
| 85 | - tkController.addListener( | ||
| 86 | - () { | ||
| 87 | - if (tkController.value == TikTokPagePosition.middle) { | ||
| 88 | - _videoListController.currentPlayer.play(); | ||
| 89 | - } else { | ||
| 90 | - _videoListController.currentPlayer.pause(); | ||
| 91 | } | 81 | } |
| 82 | + _videoListController.init( | ||
| 83 | + pageController: _pageController, | ||
| 84 | + initialList: videoDataList | ||
| 85 | + .map( | ||
| 86 | + (e) => VPVideoController( | ||
| 87 | + videoInfo: e, | ||
| 88 | + builder: () => VideoPlayerController.network(e.url), | ||
| 89 | + ), | ||
| 90 | + ) | ||
| 91 | + .toList(), | ||
| 92 | + videoProvider: (int index, List<VPVideoController> list) async { | ||
| 93 | + return videoDataList | ||
| 94 | + .map( | ||
| 95 | + (e) => VPVideoController( | ||
| 96 | + videoInfo: e, | ||
| 97 | + builder: () => VideoPlayerController.network(e.url), | ||
| 98 | + ), | ||
| 99 | + ) | ||
| 100 | + .toList(); | ||
| 101 | + }, | ||
| 102 | + ); | ||
| 103 | + | ||
| 104 | + _videoListController.addListener(() { | ||
| 105 | + setState(() {}); | ||
| 106 | + }); | ||
| 107 | + tkController.addListener( | ||
| 108 | + () { | ||
| 109 | + if (tkController.value == TikTokPagePosition.middle) { | ||
| 110 | + _videoListController.currentPlayer.play(); | ||
| 111 | + } else { | ||
| 112 | + _videoListController.currentPlayer.pause(); | ||
| 113 | + } | ||
| 114 | + }, | ||
| 115 | + ); | ||
| 116 | + | ||
| 117 | + bus = eventBus.on<TransEvent>().listen((event) { | ||
| 118 | + _videoListController.currentPlayer.pause(); | ||
| 119 | + }); | ||
| 120 | + }, | ||
| 121 | + onError: (code, msg) { | ||
| 122 | + Toast.show("获取数据失败,请稍候再试..."); | ||
| 123 | + isLoading = false; | ||
| 92 | }, | 124 | }, |
| 93 | ); | 125 | ); |
| 94 | - | ||
| 95 | - bus = eventBus.on<TransEvent>().listen((event) { | ||
| 96 | - _videoListController.currentPlayer.pause(); | ||
| 97 | - }); | ||
| 98 | - | ||
| 99 | super.initState(); | 126 | super.initState(); |
| 100 | } | 127 | } |
| 101 | 128 | ||
| ... | @@ -124,100 +151,102 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -124,100 +151,102 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
| 124 | ); | 151 | ); |
| 125 | 152 | ||
| 126 | // 组合 | 153 | // 组合 |
| 127 | - return TikTokScaffold( | 154 | + return isLoading |
| 128 | - controller: tkController, | 155 | + ? const GFLoader() |
| 129 | - header: MyAppBar( | 156 | + : TikTokScaffold( |
| 130 | - isBack: false, | 157 | + controller: tkController, |
| 131 | - isTransparent: true, | 158 | + header: MyAppBar( |
| 132 | - homeMenuHeader: HomeTypesHeader( | 159 | + isBack: false, |
| 133 | - funcCenter: () { | 160 | + isTransparent: true, |
| 134 | - _videoListController.currentPlayer.pause(); | 161 | + homeMenuHeader: HomeTypesHeader( |
| 135 | - NavigatorUtils.push( | 162 | + funcCenter: () { |
| 136 | - context, | 163 | + _videoListController.currentPlayer.pause(); |
| 137 | - CategoryRouter.categoryPage, | 164 | + NavigatorUtils.push( |
| 138 | - ); | 165 | + context, |
| 139 | - }, | 166 | + CategoryRouter.categoryPage, |
| 140 | - ), | 167 | + ); |
| 141 | - homeActionWidgets: IconButton( | ||
| 142 | - icon: const Icon( | ||
| 143 | - Icons.search, | ||
| 144 | - color: Colors.white, | ||
| 145 | - ), | ||
| 146 | - onPressed: () { | ||
| 147 | - NavigatorUtils.push(context, PoemRouter.poemSearchPage); | ||
| 148 | - _videoListController.currentPlayer.pause(); | ||
| 149 | - }, | ||
| 150 | - ), | ||
| 151 | - ), | ||
| 152 | - leftPage: searchPage, | ||
| 153 | - rightPage: detailPage, | ||
| 154 | - enableGesture: true, | ||
| 155 | - page: Stack( | ||
| 156 | - children: <Widget>[ | ||
| 157 | - PageView.builder( | ||
| 158 | - key: const Key('home'), | ||
| 159 | - physics: const QuickerScrollPhysics(), | ||
| 160 | - controller: _pageController, | ||
| 161 | - scrollDirection: Axis.vertical, | ||
| 162 | - itemCount: _videoListController.videoCount, | ||
| 163 | - itemBuilder: (context, i) { | ||
| 164 | - // 拼一个视频组件出来 | ||
| 165 | - var player = _videoListController.playerOfIndex(i)!; | ||
| 166 | - var data = player.videoInfo!; | ||
| 167 | - // 右侧按钮列 | ||
| 168 | - Widget buttons = TikTokButtonColumn( | ||
| 169 | - isFavorite: false, | ||
| 170 | - onAvatar: () { | ||
| 171 | - tkController.animateToPage(TikTokPagePosition.right); | ||
| 172 | }, | 168 | }, |
| 173 | - onFavorite: () {}, | 169 | + ), |
| 174 | - onShare: () {}, | 170 | + homeActionWidgets: IconButton( |
| 175 | - ); | 171 | + icon: const Icon( |
| 176 | - Widget poem = TikTokVidePoem( | 172 | + Icons.search, |
| 177 | - title: "每日一言", | 173 | + color: Colors.white, |
| 178 | - poem: | ||
| 179 | - "清晨入古寺,初日照高林。\n曲径通幽处,禅房花木深。\n山光悦鸟性,潭影空人心。\n万籁此都寂,但余钟磬音。\n", | ||
| 180 | - author: "----《题破山寺后禅院》常建", | ||
| 181 | - onShowDetail: () { | ||
| 182 | - tkController.animateToPage(TikTokPagePosition.right); | ||
| 183 | - }, | ||
| 184 | - ); | ||
| 185 | - Widget topInfo = const TikTokTopInfoColumn(info: "早安"); | ||
| 186 | - // video | ||
| 187 | - Widget currentVideo = Center( | ||
| 188 | - child: AspectRatio( | ||
| 189 | - aspectRatio: player.controller.value.aspectRatio, | ||
| 190 | - child: VideoPlayer(player.controller), | ||
| 191 | ), | 174 | ), |
| 192 | - ); | 175 | + onPressed: () { |
| 193 | - | 176 | + NavigatorUtils.push(context, PoemRouter.poemSearchPage); |
| 194 | - currentVideo = TikTokVideoPage( | 177 | + _videoListController.currentPlayer.pause(); |
| 195 | - // 手势播放与自然播放都会产生暂停按钮状态变化,待处理 | ||
| 196 | - hidePauseIcon: !player.showPauseIcon.value, | ||
| 197 | - aspectRatio: 9 / 16.0, | ||
| 198 | - key: Key(data.url + '$i'), | ||
| 199 | - tag: data.url, | ||
| 200 | - bottomPadding: hasBottomPadding ? 16.px : 16.px, | ||
| 201 | - onSingleTap: () async { | ||
| 202 | - if (player.controller.value.isPlaying) { | ||
| 203 | - await player.pause(); | ||
| 204 | - } else { | ||
| 205 | - await player.play(); | ||
| 206 | - } | ||
| 207 | - setState(() {}); | ||
| 208 | }, | 178 | }, |
| 209 | - onAddFavorite: () {}, | 179 | + ), |
| 210 | - rightButtonColumn: buttons, | 180 | + ), |
| 211 | - leftPoemArea: poem, | 181 | + leftPage: searchPage, |
| 212 | - topInfo: topInfo, | 182 | + rightPage: detailPage, |
| 213 | - video: currentVideo, | 183 | + enableGesture: true, |
| 214 | - ); | 184 | + page: Stack( |
| 215 | - return currentVideo; | 185 | + children: <Widget>[ |
| 216 | - }, | 186 | + PageView.builder( |
| 217 | - ), | 187 | + key: const Key('home'), |
| 218 | - currentPage ?? Container(), | 188 | + physics: const QuickerScrollPhysics(), |
| 219 | - ], | 189 | + controller: _pageController, |
| 220 | - ), | 190 | + scrollDirection: Axis.vertical, |
| 221 | - ); | 191 | + itemCount: _videoListController.videoCount, |
| 192 | + itemBuilder: (context, i) { | ||
| 193 | + // 拼一个视频组件出来 | ||
| 194 | + var player = _videoListController.playerOfIndex(i)!; | ||
| 195 | + var data = player.videoInfo!; | ||
| 196 | + // 右侧按钮列 | ||
| 197 | + Widget buttons = TikTokButtonColumn( | ||
| 198 | + isFavorite: false, | ||
| 199 | + onAvatar: () { | ||
| 200 | + tkController.animateToPage(TikTokPagePosition.right); | ||
| 201 | + }, | ||
| 202 | + onFavorite: () {}, | ||
| 203 | + onShare: () {}, | ||
| 204 | + ); | ||
| 205 | + Widget poem = TikTokVidePoem( | ||
| 206 | + title: "每日一言", | ||
| 207 | + poem: | ||
| 208 | + "清晨入古寺,初日照高林。\n曲径通幽处,禅房花木深。\n山光悦鸟性,潭影空人心。\n万籁此都寂,但余钟磬音。\n", | ||
| 209 | + author: "----《题破山寺后禅院》常建", | ||
| 210 | + onShowDetail: () { | ||
| 211 | + tkController.animateToPage(TikTokPagePosition.right); | ||
| 212 | + }, | ||
| 213 | + ); | ||
| 214 | + Widget topInfo = const TikTokTopInfoColumn(info: "早安"); | ||
| 215 | + // video | ||
| 216 | + Widget currentVideo = Center( | ||
| 217 | + child: AspectRatio( | ||
| 218 | + aspectRatio: player.controller.value.aspectRatio, | ||
| 219 | + child: VideoPlayer(player.controller), | ||
| 220 | + ), | ||
| 221 | + ); | ||
| 222 | + | ||
| 223 | + currentVideo = TikTokVideoPage( | ||
| 224 | + // 手势播放与自然播放都会产生暂停按钮状态变化,待处理 | ||
| 225 | + hidePauseIcon: !player.showPauseIcon.value, | ||
| 226 | + aspectRatio: 9 / 16.0, | ||
| 227 | + key: Key('${data.url}$i'), | ||
| 228 | + tag: data.url, | ||
| 229 | + bottomPadding: hasBottomPadding ? 16.px : 16.px, | ||
| 230 | + onSingleTap: () async { | ||
| 231 | + if (player.controller.value.isPlaying) { | ||
| 232 | + await player.pause(); | ||
| 233 | + } else { | ||
| 234 | + await player.play(); | ||
| 235 | + } | ||
| 236 | + setState(() {}); | ||
| 237 | + }, | ||
| 238 | + onAddFavorite: () {}, | ||
| 239 | + rightButtonColumn: buttons, | ||
| 240 | + // leftPoemArea: poem, | ||
| 241 | + // topInfo: topInfo, | ||
| 242 | + video: currentVideo, | ||
| 243 | + ); | ||
| 244 | + return currentVideo; | ||
| 245 | + }, | ||
| 246 | + ), | ||
| 247 | + currentPage ?? Container(), | ||
| 248 | + ], | ||
| 249 | + ), | ||
| 250 | + ); | ||
| 222 | } | 251 | } |
| 223 | } | 252 | } | ... | ... |
-
Please register or login to post a comment