Showing
7 changed files
with
462 additions
and
13 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'; |
... | @@ -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>( |
... | @@ -310,7 +350,8 @@ class JsonConvert { | ... | @@ -310,7 +350,8 @@ class JsonConvert { |
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>( |
354 | + json.map((e) => e as Map<String, dynamic>).toList()); | ||
314 | } else { | 355 | } else { |
315 | return jsonConvert.asT<M>(json); | 356 | return jsonConvert.asT<M>(json); |
316 | } | 357 | } | ... | ... |
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,15 +60,32 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -56,15 +60,32 @@ 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); |
64 | + isLoading = true; | ||
65 | + DioUtils.instance.asyncRequestNetwork<HomeEntity>( | ||
66 | + Method.get, | ||
67 | + HttpApi.home, | ||
68 | + params: [], | ||
69 | + onSuccess: (data) { | ||
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, | ||
79 | + ), | ||
80 | + ); | ||
81 | + } | ||
61 | _videoListController.init( | 82 | _videoListController.init( |
62 | pageController: _pageController, | 83 | pageController: _pageController, |
63 | initialList: videoDataList | 84 | initialList: videoDataList |
64 | .map( | 85 | .map( |
65 | (e) => VPVideoController( | 86 | (e) => VPVideoController( |
66 | videoInfo: e, | 87 | videoInfo: e, |
67 | - builder: () => VideoPlayerController.asset(e.url), | 88 | + builder: () => VideoPlayerController.network(e.url), |
68 | ), | 89 | ), |
69 | ) | 90 | ) |
70 | .toList(), | 91 | .toList(), |
... | @@ -73,12 +94,13 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -73,12 +94,13 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
73 | .map( | 94 | .map( |
74 | (e) => VPVideoController( | 95 | (e) => VPVideoController( |
75 | videoInfo: e, | 96 | videoInfo: e, |
76 | - builder: () => VideoPlayerController.asset(e.url), | 97 | + builder: () => VideoPlayerController.network(e.url), |
77 | ), | 98 | ), |
78 | ) | 99 | ) |
79 | .toList(); | 100 | .toList(); |
80 | }, | 101 | }, |
81 | ); | 102 | ); |
103 | + | ||
82 | _videoListController.addListener(() { | 104 | _videoListController.addListener(() { |
83 | setState(() {}); | 105 | setState(() {}); |
84 | }); | 106 | }); |
... | @@ -95,7 +117,12 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -95,7 +117,12 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
95 | bus = eventBus.on<TransEvent>().listen((event) { | 117 | bus = eventBus.on<TransEvent>().listen((event) { |
96 | _videoListController.currentPlayer.pause(); | 118 | _videoListController.currentPlayer.pause(); |
97 | }); | 119 | }); |
98 | - | 120 | + }, |
121 | + onError: (code, msg) { | ||
122 | + Toast.show("获取数据失败,请稍候再试..."); | ||
123 | + isLoading = false; | ||
124 | + }, | ||
125 | + ); | ||
99 | super.initState(); | 126 | super.initState(); |
100 | } | 127 | } |
101 | 128 | ||
... | @@ -124,7 +151,9 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -124,7 +151,9 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
124 | ); | 151 | ); |
125 | 152 | ||
126 | // 组合 | 153 | // 组合 |
127 | - return TikTokScaffold( | 154 | + return isLoading |
155 | + ? const GFLoader() | ||
156 | + : TikTokScaffold( | ||
128 | controller: tkController, | 157 | controller: tkController, |
129 | header: MyAppBar( | 158 | header: MyAppBar( |
130 | isBack: false, | 159 | isBack: false, |
... | @@ -195,7 +224,7 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -195,7 +224,7 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
195 | // 手势播放与自然播放都会产生暂停按钮状态变化,待处理 | 224 | // 手势播放与自然播放都会产生暂停按钮状态变化,待处理 |
196 | hidePauseIcon: !player.showPauseIcon.value, | 225 | hidePauseIcon: !player.showPauseIcon.value, |
197 | aspectRatio: 9 / 16.0, | 226 | aspectRatio: 9 / 16.0, |
198 | - key: Key(data.url + '$i'), | 227 | + key: Key('${data.url}$i'), |
199 | tag: data.url, | 228 | tag: data.url, |
200 | bottomPadding: hasBottomPadding ? 16.px : 16.px, | 229 | bottomPadding: hasBottomPadding ? 16.px : 16.px, |
201 | onSingleTap: () async { | 230 | onSingleTap: () async { |
... | @@ -208,8 +237,8 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { | ... | @@ -208,8 +237,8 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { |
208 | }, | 237 | }, |
209 | onAddFavorite: () {}, | 238 | onAddFavorite: () {}, |
210 | rightButtonColumn: buttons, | 239 | rightButtonColumn: buttons, |
211 | - leftPoemArea: poem, | 240 | + // leftPoemArea: poem, |
212 | - topInfo: topInfo, | 241 | + // topInfo: topInfo, |
213 | video: currentVideo, | 242 | video: currentVideo, |
214 | ); | 243 | ); |
215 | return currentVideo; | 244 | return currentVideo; | ... | ... |
-
Please register or login to post a comment