Showing
6 changed files
with
235 additions
and
22 deletions
lib/account/models/collect_entity.dart
0 → 100644
1 | +import 'package:Parlando/generated/json/base/json_field.dart'; | ||
2 | +import 'package:Parlando/generated/json/collect_entity.g.dart'; | ||
3 | +import 'dart:convert'; | ||
4 | + | ||
5 | +@JsonSerializable() | ||
6 | +class CollectEntity { | ||
7 | + String? status; | ||
8 | + int? code; | ||
9 | + String? message; | ||
10 | + List<CollectData>? data; | ||
11 | + CollectError? error; | ||
12 | + | ||
13 | + CollectEntity(); | ||
14 | + | ||
15 | + factory CollectEntity.fromJson(Map<String, dynamic> json) => | ||
16 | + $CollectEntityFromJson(json); | ||
17 | + | ||
18 | + Map<String, dynamic> toJson() => $CollectEntityToJson(this); | ||
19 | + | ||
20 | + @override | ||
21 | + String toString() { | ||
22 | + return jsonEncode(this); | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +@JsonSerializable() | ||
27 | +class CollectData { | ||
28 | + @JSONField(name: "user_id") | ||
29 | + int? userId; | ||
30 | + @JSONField(name: "immerse_id") | ||
31 | + int? immerseId; | ||
32 | + String? content; | ||
33 | + String? thumbnail; | ||
34 | + String? url; | ||
35 | + int? type; | ||
36 | + @JSONField(name: "is_praise") | ||
37 | + bool? isPraise; | ||
38 | + @JSONField(name: "is_collect") | ||
39 | + bool? isCollect; | ||
40 | + | ||
41 | + CollectData(); | ||
42 | + | ||
43 | + factory CollectData.fromJson(Map<String, dynamic> json) => | ||
44 | + $CollectDataFromJson(json); | ||
45 | + | ||
46 | + Map<String, dynamic> toJson() => $CollectDataToJson(this); | ||
47 | + | ||
48 | + @override | ||
49 | + String toString() { | ||
50 | + return jsonEncode(this); | ||
51 | + } | ||
52 | +} | ||
53 | + | ||
54 | +@JsonSerializable() | ||
55 | +class CollectError { | ||
56 | + CollectError(); | ||
57 | + | ||
58 | + factory CollectError.fromJson(Map<String, dynamic> json) => | ||
59 | + $CollectErrorFromJson(json); | ||
60 | + | ||
61 | + Map<String, dynamic> toJson() => $CollectErrorToJson(this); | ||
62 | + | ||
63 | + @override | ||
64 | + String toString() { | ||
65 | + return jsonEncode(this); | ||
66 | + } | ||
67 | +} |
1 | +import 'package:Parlando/account/models/collect_entity.dart'; | ||
1 | import 'package:Parlando/account/models/my_videos_entity.dart'; | 2 | import 'package:Parlando/account/models/my_videos_entity.dart'; |
2 | import 'package:Parlando/account/models/user_entity.dart'; | 3 | import 'package:Parlando/account/models/user_entity.dart'; |
3 | import 'package:Parlando/account/view_models/account_view_model.dart'; | 4 | import 'package:Parlando/account/view_models/account_view_model.dart'; |
... | @@ -44,6 +45,7 @@ class AccountPage extends StatefulWidget { | ... | @@ -44,6 +45,7 @@ class AccountPage extends StatefulWidget { |
44 | class AccountPageState extends State<AccountPage> { | 45 | class AccountPageState extends State<AccountPage> { |
45 | bool isLoadMyVideos = false; | 46 | bool isLoadMyVideos = false; |
46 | List<Widget> videos = <Widget>[]; | 47 | List<Widget> videos = <Widget>[]; |
48 | + int cate = 0; | ||
47 | 49 | ||
48 | @override | 50 | @override |
49 | void initState() { | 51 | void initState() { |
... | @@ -54,7 +56,38 @@ class AccountPageState extends State<AccountPage> { | ... | @@ -54,7 +56,38 @@ class AccountPageState extends State<AccountPage> { |
54 | .setSelectedAccount(null); | 56 | .setSelectedAccount(null); |
55 | Provider.of<AccountViewProvider>(context, listen: false) | 57 | Provider.of<AccountViewProvider>(context, listen: false) |
56 | .fetchAccountData('0'); | 58 | .fetchAccountData('0'); |
59 | + _fetchMyVideos(); | ||
60 | + } else { | ||
61 | + NavigatorUtils.push(context, LoginRouter.loginPage, replace: true); | ||
62 | + } | ||
63 | + } | ||
57 | 64 | ||
65 | + void _fetchCollect() { | ||
66 | + videos.clear(); | ||
67 | + isLoadMyVideos = true; | ||
68 | + // 加载作品 | ||
69 | + DioUtils.instance.asyncRequestNetwork<CollectEntity>( | ||
70 | + Method.get, | ||
71 | + HttpApi.collect, | ||
72 | + params: [], | ||
73 | + onSuccess: (data) { | ||
74 | + for (CollectData each in data!.data!) { | ||
75 | + videos.add(_SmallVideo( | ||
76 | + url: each.thumbnail!, | ||
77 | + id: each.immerseId!, | ||
78 | + )); | ||
79 | + } | ||
80 | + isLoadMyVideos = false; | ||
81 | + setState(() {}); | ||
82 | + }, | ||
83 | + onError: (code, msg) { | ||
84 | + isLoadMyVideos = false; | ||
85 | + }, | ||
86 | + ); | ||
87 | + } | ||
88 | + | ||
89 | + void _fetchMyVideos() { | ||
90 | + videos.clear(); | ||
58 | isLoadMyVideos = true; | 91 | isLoadMyVideos = true; |
59 | // 加载作品 | 92 | // 加载作品 |
60 | DioUtils.instance.asyncRequestNetwork<MyVideosEntity>( | 93 | DioUtils.instance.asyncRequestNetwork<MyVideosEntity>( |
... | @@ -75,9 +108,6 @@ class AccountPageState extends State<AccountPage> { | ... | @@ -75,9 +108,6 @@ class AccountPageState extends State<AccountPage> { |
75 | isLoadMyVideos = false; | 108 | isLoadMyVideos = false; |
76 | }, | 109 | }, |
77 | ); | 110 | ); |
78 | - } else { | ||
79 | - NavigatorUtils.push(context, LoginRouter.loginPage, replace: true); | ||
80 | - } | ||
81 | } | 111 | } |
82 | 112 | ||
83 | @override | 113 | @override |
... | @@ -227,30 +257,28 @@ class AccountPageState extends State<AccountPage> { | ... | @@ -227,30 +257,28 @@ class AccountPageState extends State<AccountPage> { |
227 | Container( | 257 | Container( |
228 | color: ColorPlate.white, | 258 | color: ColorPlate.white, |
229 | padding: EdgeInsets.symmetric( | 259 | padding: EdgeInsets.symmetric( |
230 | - horizontal: 8.px, | 260 | + horizontal: 2.px, |
231 | vertical: 2.px, | 261 | vertical: 2.px, |
232 | ), | 262 | ), |
233 | child: Row( | 263 | child: Row( |
234 | mainAxisAlignment: MainAxisAlignment.start, | 264 | mainAxisAlignment: MainAxisAlignment.start, |
235 | crossAxisAlignment: CrossAxisAlignment.center, | 265 | crossAxisAlignment: CrossAxisAlignment.center, |
236 | - children: const <Widget>[ | 266 | + children: <Widget>[ |
237 | - TextGroup('356', '关注'), | 267 | + TextButton( |
238 | - TextGroup('145万', '粉丝'), | 268 | + onPressed: () { |
239 | - TextGroup('1423万', '获赞'), | 269 | + _fetchMyVideos(); |
270 | + setState(() {}); | ||
271 | + }, | ||
272 | + child: const Text("作品")), | ||
273 | + TextButton( | ||
274 | + onPressed: () { | ||
275 | + _fetchCollect(); | ||
276 | + setState(() {}); | ||
277 | + }, | ||
278 | + child: const Text("收藏")), | ||
240 | ], | 279 | ], |
241 | ), | 280 | ), |
242 | ), | 281 | ), |
243 | - Container( | ||
244 | - height: 10.px, | ||
245 | - margin: const EdgeInsets.symmetric(horizontal: 12), | ||
246 | - decoration: BoxDecoration( | ||
247 | - border: Border( | ||
248 | - bottom: BorderSide( | ||
249 | - color: Colors.white.withOpacity(0.1), | ||
250 | - ), | ||
251 | - ), | ||
252 | - ), | ||
253 | - ), | ||
254 | SizedBox( | 282 | SizedBox( |
255 | width: double.infinity, | 283 | width: double.infinity, |
256 | height: 500, | 284 | height: 500, |
... | @@ -433,8 +461,7 @@ class TextGroup extends StatelessWidget { | ... | @@ -433,8 +461,7 @@ class TextGroup extends StatelessWidget { |
433 | final String title, tag; | 461 | final String title, tag; |
434 | final Color? color; | 462 | final Color? color; |
435 | 463 | ||
436 | - const TextGroup( | 464 | + const TextGroup(this.title, |
437 | - this.title, | ||
438 | this.tag, { | 465 | this.tag, { |
439 | Key? key, | 466 | Key? key, |
440 | this.color, | 467 | this.color, | ... | ... |
... | @@ -4,6 +4,7 @@ | ... | @@ -4,6 +4,7 @@ |
4 | 4 | ||
5 | // This file is automatically generated. DO NOT EDIT, all your changes would be lost. | 5 | // This file is automatically generated. DO NOT EDIT, all your changes would be lost. |
6 | import 'package:flutter/material.dart' show debugPrint; | 6 | import 'package:flutter/material.dart' show debugPrint; |
7 | +import 'package:Parlando/account/models/collect_entity.dart'; | ||
7 | import 'package:Parlando/account/models/my_videos_entity.dart'; | 8 | import 'package:Parlando/account/models/my_videos_entity.dart'; |
8 | import 'package:Parlando/account/models/upload_avatar_entity.dart'; | 9 | import 'package:Parlando/account/models/upload_avatar_entity.dart'; |
9 | import 'package:Parlando/account/models/user_entity.dart'; | 10 | import 'package:Parlando/account/models/user_entity.dart'; |
... | @@ -27,6 +28,9 @@ typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json); | ... | @@ -27,6 +28,9 @@ typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json); |
27 | 28 | ||
28 | class JsonConvert { | 29 | class JsonConvert { |
29 | static final Map<String, JsonConvertFunction> _convertFuncMap = { | 30 | static final Map<String, JsonConvertFunction> _convertFuncMap = { |
31 | + (CollectEntity).toString(): CollectEntity.fromJson, | ||
32 | + (CollectData).toString(): CollectData.fromJson, | ||
33 | + (CollectError).toString(): CollectError.fromJson, | ||
30 | (MyVideosEntity).toString(): MyVideosEntity.fromJson, | 34 | (MyVideosEntity).toString(): MyVideosEntity.fromJson, |
31 | (MyVideosData).toString(): MyVideosData.fromJson, | 35 | (MyVideosData).toString(): MyVideosData.fromJson, |
32 | (MyVideosError).toString(): MyVideosError.fromJson, | 36 | (MyVideosError).toString(): MyVideosError.fromJson, |
... | @@ -161,6 +165,23 @@ class JsonConvert { | ... | @@ -161,6 +165,23 @@ class JsonConvert { |
161 | 165 | ||
162 | //list is returned by type | 166 | //list is returned by type |
163 | static M? _getListChildType<M>(List<Map<String, dynamic>> data) { | 167 | static M? _getListChildType<M>(List<Map<String, dynamic>> data) { |
168 | + if (<CollectEntity>[] is M) { | ||
169 | + return data | ||
170 | + .map<CollectEntity>( | ||
171 | + (Map<String, dynamic> e) => CollectEntity.fromJson(e)) | ||
172 | + .toList() as M; | ||
173 | + } | ||
174 | + if (<CollectData>[] is M) { | ||
175 | + return data | ||
176 | + .map<CollectData>((Map<String, dynamic> e) => CollectData.fromJson(e)) | ||
177 | + .toList() as M; | ||
178 | + } | ||
179 | + if (<CollectError>[] is M) { | ||
180 | + return data | ||
181 | + .map<CollectError>( | ||
182 | + (Map<String, dynamic> e) => CollectError.fromJson(e)) | ||
183 | + .toList() as M; | ||
184 | + } | ||
164 | if (<MyVideosEntity>[] is M) { | 185 | if (<MyVideosEntity>[] is M) { |
165 | return data | 186 | return data |
166 | .map<MyVideosEntity>( | 187 | .map<MyVideosEntity>( | ... | ... |
lib/generated/json/collect_entity.g.dart
0 → 100644
1 | +import 'package:Parlando/generated/json/base/json_convert_content.dart'; | ||
2 | +import 'package:Parlando/account/models/collect_entity.dart'; | ||
3 | + | ||
4 | +CollectEntity $CollectEntityFromJson(Map<String, dynamic> json) { | ||
5 | + final CollectEntity collectEntity = CollectEntity(); | ||
6 | + final String? status = jsonConvert.convert<String>(json['status']); | ||
7 | + if (status != null) { | ||
8 | + collectEntity.status = status; | ||
9 | + } | ||
10 | + final int? code = jsonConvert.convert<int>(json['code']); | ||
11 | + if (code != null) { | ||
12 | + collectEntity.code = code; | ||
13 | + } | ||
14 | + final String? message = jsonConvert.convert<String>(json['message']); | ||
15 | + if (message != null) { | ||
16 | + collectEntity.message = message; | ||
17 | + } | ||
18 | + final List<CollectData>? data = | ||
19 | + jsonConvert.convertListNotNull<CollectData>(json['data']); | ||
20 | + if (data != null) { | ||
21 | + collectEntity.data = data; | ||
22 | + } | ||
23 | + final CollectError? error = jsonConvert.convert<CollectError>(json['error']); | ||
24 | + if (error != null) { | ||
25 | + collectEntity.error = error; | ||
26 | + } | ||
27 | + return collectEntity; | ||
28 | +} | ||
29 | + | ||
30 | +Map<String, dynamic> $CollectEntityToJson(CollectEntity entity) { | ||
31 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
32 | + data['status'] = entity.status; | ||
33 | + data['code'] = entity.code; | ||
34 | + data['message'] = entity.message; | ||
35 | + data['data'] = entity.data?.map((v) => v.toJson()).toList(); | ||
36 | + data['error'] = entity.error?.toJson(); | ||
37 | + return data; | ||
38 | +} | ||
39 | + | ||
40 | +CollectData $CollectDataFromJson(Map<String, dynamic> json) { | ||
41 | + final CollectData collectData = CollectData(); | ||
42 | + final int? userId = jsonConvert.convert<int>(json['user_id']); | ||
43 | + if (userId != null) { | ||
44 | + collectData.userId = userId; | ||
45 | + } | ||
46 | + final int? immerseId = jsonConvert.convert<int>(json['immerse_id']); | ||
47 | + if (immerseId != null) { | ||
48 | + collectData.immerseId = immerseId; | ||
49 | + } | ||
50 | + final String? content = jsonConvert.convert<String>(json['content']); | ||
51 | + if (content != null) { | ||
52 | + collectData.content = content; | ||
53 | + } | ||
54 | + final String? thumbnail = jsonConvert.convert<String>(json['thumbnail']); | ||
55 | + if (thumbnail != null) { | ||
56 | + collectData.thumbnail = thumbnail; | ||
57 | + } | ||
58 | + final String? url = jsonConvert.convert<String>(json['url']); | ||
59 | + if (url != null) { | ||
60 | + collectData.url = url; | ||
61 | + } | ||
62 | + final int? type = jsonConvert.convert<int>(json['type']); | ||
63 | + if (type != null) { | ||
64 | + collectData.type = type; | ||
65 | + } | ||
66 | + final bool? isPraise = jsonConvert.convert<bool>(json['is_praise']); | ||
67 | + if (isPraise != null) { | ||
68 | + collectData.isPraise = isPraise; | ||
69 | + } | ||
70 | + final bool? isCollect = jsonConvert.convert<bool>(json['is_collect']); | ||
71 | + if (isCollect != null) { | ||
72 | + collectData.isCollect = isCollect; | ||
73 | + } | ||
74 | + return collectData; | ||
75 | +} | ||
76 | + | ||
77 | +Map<String, dynamic> $CollectDataToJson(CollectData entity) { | ||
78 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
79 | + data['user_id'] = entity.userId; | ||
80 | + data['immerse_id'] = entity.immerseId; | ||
81 | + data['content'] = entity.content; | ||
82 | + data['thumbnail'] = entity.thumbnail; | ||
83 | + data['url'] = entity.url; | ||
84 | + data['type'] = entity.type; | ||
85 | + data['is_praise'] = entity.isPraise; | ||
86 | + data['is_collect'] = entity.isCollect; | ||
87 | + return data; | ||
88 | +} | ||
89 | + | ||
90 | +CollectError $CollectErrorFromJson(Map<String, dynamic> json) { | ||
91 | + final CollectError collectError = CollectError(); | ||
92 | + return collectError; | ||
93 | +} | ||
94 | + | ||
95 | +Map<String, dynamic> $CollectErrorToJson(CollectError entity) { | ||
96 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
97 | + return data; | ||
98 | +} |
... | @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev | ... | @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev |
15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. | 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. |
16 | # Read more about iOS versioning at | 16 | # Read more about iOS versioning at |
17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html |
18 | -version: 1.0.0+8 | 18 | +version: 1.0.0+10 |
19 | 19 | ||
20 | environment: | 20 | environment: |
21 | sdk: ">=2.16.2 <3.0.0" | 21 | sdk: ">=2.16.2 <3.0.0" | ... | ... |
-
Please register or login to post a comment