Showing
12 changed files
with
231 additions
and
127 deletions
... | @@ -8,12 +8,12 @@ import 'package:Parlando/account/models/user_entity.dart'; | ... | @@ -8,12 +8,12 @@ import 'package:Parlando/account/models/user_entity.dart'; |
8 | import 'package:Parlando/category/models/category_item_entity.dart'; | 8 | import 'package:Parlando/category/models/category_item_entity.dart'; |
9 | import 'package:Parlando/home/models/setting_entity.dart'; | 9 | import 'package:Parlando/home/models/setting_entity.dart'; |
10 | import 'package:Parlando/login/models/auth_entity.dart'; | 10 | import 'package:Parlando/login/models/auth_entity.dart'; |
11 | +import 'package:Parlando/models/upload_entity.dart'; | ||
11 | import 'package:Parlando/poem/models/lang_sort_entity.dart'; | 12 | import 'package:Parlando/poem/models/lang_sort_entity.dart'; |
12 | import 'package:Parlando/poem/models/search_entity.dart'; | 13 | import 'package:Parlando/poem/models/search_entity.dart'; |
13 | import 'package:Parlando/timeline/models/friend_entity.dart'; | 14 | import 'package:Parlando/timeline/models/friend_entity.dart'; |
14 | 15 | ||
15 | JsonConvert jsonConvert = JsonConvert(); | 16 | JsonConvert jsonConvert = JsonConvert(); |
16 | - | ||
17 | typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json); | 17 | typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json); |
18 | 18 | ||
19 | class JsonConvert { | 19 | class JsonConvert { |
... | @@ -29,6 +29,9 @@ class JsonConvert { | ... | @@ -29,6 +29,9 @@ class JsonConvert { |
29 | (AuthEntity).toString(): AuthEntity.fromJson, | 29 | (AuthEntity).toString(): AuthEntity.fromJson, |
30 | (AuthData).toString(): AuthData.fromJson, | 30 | (AuthData).toString(): AuthData.fromJson, |
31 | (AuthError).toString(): AuthError.fromJson, | 31 | (AuthError).toString(): AuthError.fromJson, |
32 | + (UploadEntity).toString(): UploadEntity.fromJson, | ||
33 | + (UploadData).toString(): UploadData.fromJson, | ||
34 | + (UploadError).toString(): UploadError.fromJson, | ||
32 | (LangSortEntity).toString(): LangSortEntity.fromJson, | 35 | (LangSortEntity).toString(): LangSortEntity.fromJson, |
33 | (SearchEntity).toString(): SearchEntity.fromJson, | 36 | (SearchEntity).toString(): SearchEntity.fromJson, |
34 | (SearchItems).toString(): SearchItems.fromJson, | 37 | (SearchItems).toString(): SearchItems.fromJson, |
... | @@ -111,115 +114,78 @@ class JsonConvert { | ... | @@ -111,115 +114,78 @@ class JsonConvert { |
111 | 114 | ||
112 | //list is returned by type | 115 | //list is returned by type |
113 | static M? _getListChildType<M>(List<Map<String, dynamic>> data) { | 116 | static M? _getListChildType<M>(List<Map<String, dynamic>> data) { |
114 | - if (<UserEntity>[] is M) { | 117 | + if(<UserEntity>[] is M){ |
115 | - return data | 118 | + return data.map<UserEntity>((Map<String, dynamic> e) => UserEntity.fromJson(e)).toList() as M; |
116 | - .map<UserEntity>((Map<String, dynamic> e) => UserEntity.fromJson(e)) | 119 | + } |
117 | - .toList() as M; | 120 | + if(<UserData>[] is M){ |
118 | - } | 121 | + return data.map<UserData>((Map<String, dynamic> e) => UserData.fromJson(e)).toList() as M; |
119 | - if (<UserData>[] is M) { | 122 | + } |
120 | - return data | 123 | + if(<UserError>[] is M){ |
121 | - .map<UserData>((Map<String, dynamic> e) => UserData.fromJson(e)) | 124 | + return data.map<UserError>((Map<String, dynamic> e) => UserError.fromJson(e)).toList() as M; |
122 | - .toList() as M; | 125 | + } |
123 | - } | 126 | + if(<CategoryItemEntity>[] is M){ |
124 | - if (<UserError>[] is M) { | 127 | + return data.map<CategoryItemEntity>((Map<String, dynamic> e) => CategoryItemEntity.fromJson(e)).toList() as M; |
125 | - return data | 128 | + } |
126 | - .map<UserError>((Map<String, dynamic> e) => UserError.fromJson(e)) | 129 | + if(<SettingEntity>[] is M){ |
127 | - .toList() as M; | 130 | + return data.map<SettingEntity>((Map<String, dynamic> e) => SettingEntity.fromJson(e)).toList() as M; |
128 | - } | 131 | + } |
129 | - if (<CategoryItemEntity>[] is M) { | 132 | + if(<SettingData>[] is M){ |
130 | - return data | 133 | + return data.map<SettingData>((Map<String, dynamic> e) => SettingData.fromJson(e)).toList() as M; |
131 | - .map<CategoryItemEntity>( | 134 | + } |
132 | - (Map<String, dynamic> e) => CategoryItemEntity.fromJson(e)) | 135 | + if(<SettingDataLoginSetting>[] is M){ |
133 | - .toList() as M; | 136 | + return data.map<SettingDataLoginSetting>((Map<String, dynamic> e) => SettingDataLoginSetting.fromJson(e)).toList() as M; |
134 | - } | 137 | + } |
135 | - if (<SettingEntity>[] is M) { | 138 | + if(<SettingError>[] is M){ |
136 | - return data | 139 | + return data.map<SettingError>((Map<String, dynamic> e) => SettingError.fromJson(e)).toList() as M; |
137 | - .map<SettingEntity>( | 140 | + } |
138 | - (Map<String, dynamic> e) => SettingEntity.fromJson(e)) | 141 | + if(<AuthEntity>[] is M){ |
139 | - .toList() as M; | 142 | + return data.map<AuthEntity>((Map<String, dynamic> e) => AuthEntity.fromJson(e)).toList() as M; |
140 | - } | 143 | + } |
141 | - if (<SettingData>[] is M) { | 144 | + if(<AuthData>[] is M){ |
142 | - return data | 145 | + return data.map<AuthData>((Map<String, dynamic> e) => AuthData.fromJson(e)).toList() as M; |
143 | - .map<SettingData>((Map<String, dynamic> e) => SettingData.fromJson(e)) | 146 | + } |
144 | - .toList() as M; | 147 | + if(<AuthError>[] is M){ |
145 | - } | 148 | + return data.map<AuthError>((Map<String, dynamic> e) => AuthError.fromJson(e)).toList() as M; |
146 | - if (<SettingDataLoginSetting>[] is M) { | 149 | + } |
147 | - return data | 150 | + if(<UploadEntity>[] is M){ |
148 | - .map<SettingDataLoginSetting>( | 151 | + return data.map<UploadEntity>((Map<String, dynamic> e) => UploadEntity.fromJson(e)).toList() as M; |
149 | - (Map<String, dynamic> e) => SettingDataLoginSetting.fromJson(e)) | 152 | + } |
150 | - .toList() as M; | 153 | + if(<UploadData>[] is M){ |
151 | - } | 154 | + return data.map<UploadData>((Map<String, dynamic> e) => UploadData.fromJson(e)).toList() as M; |
152 | - if (<SettingError>[] is M) { | 155 | + } |
153 | - return data | 156 | + if(<UploadError>[] is M){ |
154 | - .map<SettingError>( | 157 | + return data.map<UploadError>((Map<String, dynamic> e) => UploadError.fromJson(e)).toList() as M; |
155 | - (Map<String, dynamic> e) => SettingError.fromJson(e)) | 158 | + } |
156 | - .toList() as M; | 159 | + if(<LangSortEntity>[] is M){ |
157 | - } | 160 | + return data.map<LangSortEntity>((Map<String, dynamic> e) => LangSortEntity.fromJson(e)).toList() as M; |
158 | - if (<AuthEntity>[] is M) { | 161 | + } |
159 | - return data | 162 | + if(<SearchEntity>[] is M){ |
160 | - .map<AuthEntity>((Map<String, dynamic> e) => AuthEntity.fromJson(e)) | 163 | + return data.map<SearchEntity>((Map<String, dynamic> e) => SearchEntity.fromJson(e)).toList() as M; |
161 | - .toList() as M; | 164 | + } |
162 | - } | 165 | + if(<SearchItems>[] is M){ |
163 | - if (<AuthData>[] is M) { | 166 | + return data.map<SearchItems>((Map<String, dynamic> e) => SearchItems.fromJson(e)).toList() as M; |
164 | - return data | 167 | + } |
165 | - .map<AuthData>((Map<String, dynamic> e) => AuthData.fromJson(e)) | 168 | + if(<SearchItemsOwner>[] is M){ |
166 | - .toList() as M; | 169 | + return data.map<SearchItemsOwner>((Map<String, dynamic> e) => SearchItemsOwner.fromJson(e)).toList() as M; |
167 | - } | 170 | + } |
168 | - if (<AuthError>[] is M) { | 171 | + if(<SearchItemsLicense>[] is M){ |
169 | - return data | 172 | + return data.map<SearchItemsLicense>((Map<String, dynamic> e) => SearchItemsLicense.fromJson(e)).toList() as M; |
170 | - .map<AuthError>((Map<String, dynamic> e) => AuthError.fromJson(e)) | 173 | + } |
171 | - .toList() as M; | 174 | + if(<FriendEntity>[] is M){ |
172 | - } | 175 | + return data.map<FriendEntity>((Map<String, dynamic> e) => FriendEntity.fromJson(e)).toList() as M; |
173 | - if (<LangSortEntity>[] is M) { | 176 | + } |
174 | - return data | 177 | + if(<FriendData>[] is M){ |
175 | - .map<LangSortEntity>( | 178 | + return data.map<FriendData>((Map<String, dynamic> e) => FriendData.fromJson(e)).toList() as M; |
176 | - (Map<String, dynamic> e) => LangSortEntity.fromJson(e)) | ||
177 | - .toList() as M; | ||
178 | - } | ||
179 | - if (<SearchEntity>[] is M) { | ||
180 | - return data | ||
181 | - .map<SearchEntity>( | ||
182 | - (Map<String, dynamic> e) => SearchEntity.fromJson(e)) | ||
183 | - .toList() as M; | ||
184 | - } | ||
185 | - if (<SearchItems>[] is M) { | ||
186 | - return data | ||
187 | - .map<SearchItems>((Map<String, dynamic> e) => SearchItems.fromJson(e)) | ||
188 | - .toList() as M; | ||
189 | - } | ||
190 | - if (<SearchItemsOwner>[] is M) { | ||
191 | - return data | ||
192 | - .map<SearchItemsOwner>( | ||
193 | - (Map<String, dynamic> e) => SearchItemsOwner.fromJson(e)) | ||
194 | - .toList() as M; | ||
195 | - } | ||
196 | - if (<SearchItemsLicense>[] is M) { | ||
197 | - return data | ||
198 | - .map<SearchItemsLicense>( | ||
199 | - (Map<String, dynamic> e) => SearchItemsLicense.fromJson(e)) | ||
200 | - .toList() as M; | ||
201 | - } | ||
202 | - if (<FriendEntity>[] is M) { | ||
203 | - return data | ||
204 | - .map<FriendEntity>( | ||
205 | - (Map<String, dynamic> e) => FriendEntity.fromJson(e)) | ||
206 | - .toList() as M; | ||
207 | - } | ||
208 | - if (<FriendData>[] is M) { | ||
209 | - return data | ||
210 | - .map<FriendData>((Map<String, dynamic> e) => FriendData.fromJson(e)) | ||
211 | - .toList() as M; | ||
212 | } | 179 | } |
213 | 180 | ||
214 | debugPrint("${M.toString()} not found"); | 181 | debugPrint("${M.toString()} not found"); |
215 | 182 | ||
216 | return null; | 183 | return null; |
217 | - } | 184 | +} |
218 | 185 | ||
219 | static M? fromJsonAsT<M>(dynamic json) { | 186 | static M? fromJsonAsT<M>(dynamic json) { |
220 | if (json is List) { | 187 | if (json is List) { |
221 | - return _getListChildType<M>( | 188 | + return _getListChildType<M>(json.map((e) => e as Map<String, dynamic>).toList()); |
222 | - json.map((e) => e as Map<String, dynamic>).toList()); | ||
223 | } else { | 189 | } else { |
224 | return jsonConvert.asT<M>(json); | 190 | return jsonConvert.asT<M>(json); |
225 | } | 191 | } | ... | ... |
... | @@ -3,8 +3,7 @@ import 'package:Parlando/timeline/models/friend_entity.dart'; | ... | @@ -3,8 +3,7 @@ import 'package:Parlando/timeline/models/friend_entity.dart'; |
3 | 3 | ||
4 | FriendEntity $FriendEntityFromJson(Map<String, dynamic> json) { | 4 | FriendEntity $FriendEntityFromJson(Map<String, dynamic> json) { |
5 | final FriendEntity friendEntity = FriendEntity(); | 5 | final FriendEntity friendEntity = FriendEntity(); |
6 | - final List<FriendData>? data = | 6 | + final List<FriendData>? data = jsonConvert.convertListNotNull<FriendData>(json['data']); |
7 | - jsonConvert.convertListNotNull<FriendData>(json['data']); | ||
8 | if (data != null) { | 7 | if (data != null) { |
9 | friendEntity.data = data; | 8 | friendEntity.data = data; |
10 | } | 9 | } | ... | ... |
... | @@ -7,13 +7,11 @@ SearchEntity $SearchEntityFromJson(Map<String, dynamic> json) { | ... | @@ -7,13 +7,11 @@ SearchEntity $SearchEntityFromJson(Map<String, dynamic> json) { |
7 | if (totalCount != null) { | 7 | if (totalCount != null) { |
8 | searchEntity.totalCount = totalCount; | 8 | searchEntity.totalCount = totalCount; |
9 | } | 9 | } |
10 | - final bool? incompleteResults = | 10 | + final bool? incompleteResults = jsonConvert.convert<bool>(json['incomplete_results']); |
11 | - jsonConvert.convert<bool>(json['incomplete_results']); | ||
12 | if (incompleteResults != null) { | 11 | if (incompleteResults != null) { |
13 | searchEntity.incompleteResults = incompleteResults; | 12 | searchEntity.incompleteResults = incompleteResults; |
14 | } | 13 | } |
15 | - final List<SearchItems>? items = | 14 | + final List<SearchItems>? items = jsonConvert.convertListNotNull<SearchItems>(json['items']); |
16 | - jsonConvert.convertListNotNull<SearchItems>(json['items']); | ||
17 | if (items != null) { | 15 | if (items != null) { |
18 | searchEntity.items = items; | 16 | searchEntity.items = items; |
19 | } | 17 | } | ... | ... |
... | @@ -38,8 +38,7 @@ Map<String, dynamic> $SettingEntityToJson(SettingEntity entity) { | ... | @@ -38,8 +38,7 @@ Map<String, dynamic> $SettingEntityToJson(SettingEntity entity) { |
38 | 38 | ||
39 | SettingData $SettingDataFromJson(Map<String, dynamic> json) { | 39 | SettingData $SettingDataFromJson(Map<String, dynamic> json) { |
40 | final SettingData settingData = SettingData(); | 40 | final SettingData settingData = SettingData(); |
41 | - final List<SettingDataLoginSetting>? loginSetting = jsonConvert | 41 | + final List<SettingDataLoginSetting>? loginSetting = jsonConvert.convertListNotNull<SettingDataLoginSetting>(json['login_setting']); |
42 | - .convertListNotNull<SettingDataLoginSetting>(json['login_setting']); | ||
43 | if (loginSetting != null) { | 42 | if (loginSetting != null) { |
44 | settingData.loginSetting = loginSetting; | 43 | settingData.loginSetting = loginSetting; |
45 | } | 44 | } |
... | @@ -52,10 +51,8 @@ Map<String, dynamic> $SettingDataToJson(SettingData entity) { | ... | @@ -52,10 +51,8 @@ Map<String, dynamic> $SettingDataToJson(SettingData entity) { |
52 | return data; | 51 | return data; |
53 | } | 52 | } |
54 | 53 | ||
55 | -SettingDataLoginSetting $SettingDataLoginSettingFromJson( | 54 | +SettingDataLoginSetting $SettingDataLoginSettingFromJson(Map<String, dynamic> json) { |
56 | - Map<String, dynamic> json) { | 55 | + final SettingDataLoginSetting settingDataLoginSetting = SettingDataLoginSetting(); |
57 | - final SettingDataLoginSetting settingDataLoginSetting = | ||
58 | - SettingDataLoginSetting(); | ||
59 | final String? icon = jsonConvert.convert<String>(json['icon']); | 56 | final String? icon = jsonConvert.convert<String>(json['icon']); |
60 | if (icon != null) { | 57 | if (icon != null) { |
61 | settingDataLoginSetting.icon = icon; | 58 | settingDataLoginSetting.icon = icon; |
... | @@ -71,8 +68,7 @@ SettingDataLoginSetting $SettingDataLoginSettingFromJson( | ... | @@ -71,8 +68,7 @@ SettingDataLoginSetting $SettingDataLoginSettingFromJson( |
71 | return settingDataLoginSetting; | 68 | return settingDataLoginSetting; |
72 | } | 69 | } |
73 | 70 | ||
74 | -Map<String, dynamic> $SettingDataLoginSettingToJson( | 71 | +Map<String, dynamic> $SettingDataLoginSettingToJson(SettingDataLoginSetting entity) { |
75 | - SettingDataLoginSetting entity) { | ||
76 | final Map<String, dynamic> data = <String, dynamic>{}; | 72 | final Map<String, dynamic> data = <String, dynamic>{}; |
77 | data['icon'] = entity.icon; | 73 | data['icon'] = entity.icon; |
78 | data['name'] = entity.name; | 74 | data['name'] = entity.name; | ... | ... |
lib/generated/json/upload_entity.g.dart
0 → 100644
1 | +import 'package:Parlando/generated/json/base/json_convert_content.dart'; | ||
2 | +import 'package:Parlando/models/upload_entity.dart'; | ||
3 | + | ||
4 | +UploadEntity $UploadEntityFromJson(Map<String, dynamic> json) { | ||
5 | + final UploadEntity uploadEntity = UploadEntity(); | ||
6 | + final String? status = jsonConvert.convert<String>(json['status']); | ||
7 | + if (status != null) { | ||
8 | + uploadEntity.status = status; | ||
9 | + } | ||
10 | + final int? code = jsonConvert.convert<int>(json['code']); | ||
11 | + if (code != null) { | ||
12 | + uploadEntity.code = code; | ||
13 | + } | ||
14 | + final String? message = jsonConvert.convert<String>(json['message']); | ||
15 | + if (message != null) { | ||
16 | + uploadEntity.message = message; | ||
17 | + } | ||
18 | + final UploadData? data = jsonConvert.convert<UploadData>(json['data']); | ||
19 | + if (data != null) { | ||
20 | + uploadEntity.data = data; | ||
21 | + } | ||
22 | + final UploadError? error = jsonConvert.convert<UploadError>(json['error']); | ||
23 | + if (error != null) { | ||
24 | + uploadEntity.error = error; | ||
25 | + } | ||
26 | + return uploadEntity; | ||
27 | +} | ||
28 | + | ||
29 | +Map<String, dynamic> $UploadEntityToJson(UploadEntity 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 | +UploadData $UploadDataFromJson(Map<String, dynamic> json) { | ||
40 | + final UploadData uploadData = UploadData(); | ||
41 | + final String? relativePath = jsonConvert.convert<String>(json['relative_path']); | ||
42 | + if (relativePath != null) { | ||
43 | + uploadData.relativePath = relativePath; | ||
44 | + } | ||
45 | + final String? absolutePath = jsonConvert.convert<String>(json['absolute_path']); | ||
46 | + if (absolutePath != null) { | ||
47 | + uploadData.absolutePath = absolutePath; | ||
48 | + } | ||
49 | + return uploadData; | ||
50 | +} | ||
51 | + | ||
52 | +Map<String, dynamic> $UploadDataToJson(UploadData entity) { | ||
53 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
54 | + data['relative_path'] = entity.relativePath; | ||
55 | + data['absolute_path'] = entity.absolutePath; | ||
56 | + return data; | ||
57 | +} | ||
58 | + | ||
59 | +UploadError $UploadErrorFromJson(Map<String, dynamic> json) { | ||
60 | + final UploadError uploadError = UploadError(); | ||
61 | + return uploadError; | ||
62 | +} | ||
63 | + | ||
64 | +Map<String, dynamic> $UploadErrorToJson(UploadError entity) { | ||
65 | + final Map<String, dynamic> data = <String, dynamic>{}; | ||
66 | + return data; | ||
67 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
lib/models/upload_entity.dart
0 → 100644
1 | +import 'dart:convert'; | ||
2 | +import 'package:Parlando/generated/json/base/json_field.dart'; | ||
3 | +import 'package:Parlando/generated/json/upload_entity.g.dart'; | ||
4 | + | ||
5 | +@JsonSerializable() | ||
6 | +class UploadEntity { | ||
7 | + | ||
8 | + String? status; | ||
9 | + int? code; | ||
10 | + String? message; | ||
11 | + UploadData? data; | ||
12 | + UploadError? error; | ||
13 | + | ||
14 | + UploadEntity(); | ||
15 | + | ||
16 | + factory UploadEntity.fromJson(Map<String, dynamic> json) => $UploadEntityFromJson(json); | ||
17 | + | ||
18 | + Map<String, dynamic> toJson() => $UploadEntityToJson(this); | ||
19 | + | ||
20 | + @override | ||
21 | + String toString() { | ||
22 | + return jsonEncode(this); | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +@JsonSerializable() | ||
27 | +class UploadData { | ||
28 | + | ||
29 | + @JSONField(name: "relative_path") | ||
30 | + String? relativePath; | ||
31 | + @JSONField(name: "absolute_path") | ||
32 | + String? absolutePath; | ||
33 | + | ||
34 | + UploadData(); | ||
35 | + | ||
36 | + factory UploadData.fromJson(Map<String, dynamic> json) => $UploadDataFromJson(json); | ||
37 | + | ||
38 | + Map<String, dynamic> toJson() => $UploadDataToJson(this); | ||
39 | + | ||
40 | + @override | ||
41 | + String toString() { | ||
42 | + return jsonEncode(this); | ||
43 | + } | ||
44 | +} | ||
45 | + | ||
46 | +@JsonSerializable() | ||
47 | +class UploadError { | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + UploadError(); | ||
52 | + | ||
53 | + factory UploadError.fromJson(Map<String, dynamic> json) => $UploadErrorFromJson(json); | ||
54 | + | ||
55 | + Map<String, dynamic> toJson() => $UploadErrorToJson(this); | ||
56 | + | ||
57 | + @override | ||
58 | + String toString() { | ||
59 | + return jsonEncode(this); | ||
60 | + } | ||
61 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -4,6 +4,7 @@ class HttpApi { | ... | @@ -4,6 +4,7 @@ class HttpApi { |
4 | static const String verify = 'verify'; | 4 | static const String verify = 'verify'; |
5 | static const String login = 'login'; | 5 | static const String login = 'login'; |
6 | static const String uploadVideo = 'upload/video'; | 6 | static const String uploadVideo = 'upload/video'; |
7 | + static const String immersive = 'immersive'; | ||
7 | static const String user = 'user'; | 8 | static const String user = 'user'; |
8 | static const String search = 'search/repositories'; | 9 | static const String search = 'search/repositories'; |
9 | static const String subscriptions = 'users/simplezhli/subscriptions'; | 10 | static const String subscriptions = 'users/simplezhli/subscriptions'; | ... | ... |
1 | +import 'package:Parlando/models/upload_entity.dart'; | ||
1 | import 'package:Parlando/net/dio_utils.dart'; | 2 | import 'package:Parlando/net/dio_utils.dart'; |
2 | import 'package:Parlando/net/http_api.dart'; | 3 | import 'package:Parlando/net/http_api.dart'; |
4 | +import 'package:Parlando/util/toast_utils.dart'; | ||
3 | import 'package:dio/dio.dart'; | 5 | import 'package:dio/dio.dart'; |
4 | import 'package:flutter/cupertino.dart'; | 6 | import 'package:flutter/cupertino.dart'; |
5 | import 'package:flutter/material.dart'; | 7 | import 'package:flutter/material.dart'; |
... | @@ -231,14 +233,36 @@ class _PoemPublishState extends State<PoemPublish> { | ... | @@ -231,14 +233,36 @@ class _PoemPublishState extends State<PoemPublish> { |
231 | "video": value, | 233 | "video": value, |
232 | }; | 234 | }; |
233 | FormData formData = FormData.fromMap(map); | 235 | FormData formData = FormData.fromMap(map); |
234 | - DioUtils.instance.asyncRequestNetwork( | 236 | + DioUtils.instance.asyncRequestNetwork<UploadEntity>( |
235 | Method.post, | 237 | Method.post, |
236 | HttpApi.uploadVideo, | 238 | HttpApi.uploadVideo, |
237 | params: formData, | 239 | params: formData, |
238 | onSuccess: (data) { | 240 | onSuccess: (data) { |
239 | - print(data); | 241 | + String path = data!.data!.relativePath!; |
240 | - //TODO 上传视频成功之后创建临境 | 242 | + String videoId = "1"; //TODO 临时用video id |
243 | + | ||
244 | + Map<String, String> params = <String, String>{ | ||
245 | + "video_id": videoId, | ||
246 | + "video_url": path, | ||
247 | + "content": msg, | ||
248 | + }; | ||
249 | + DioUtils.instance.asyncRequestNetwork( | ||
250 | + Method.post, | ||
251 | + HttpApi.immersive, | ||
252 | + params: params, | ||
253 | + onSuccess: (data) { | ||
254 | + isPublishing = false; | ||
255 | + NavigatorUtils.push( | ||
256 | + context, | ||
257 | + '${PoemRouter.poemCompletePage}?id=100', | ||
258 | + ); | ||
259 | + }, | ||
260 | + onError: (code, msg) { | ||
261 | + Toast.show(msg.toString()); | ||
241 | isPublishing = false; | 262 | isPublishing = false; |
263 | + setState(() {}); | ||
264 | + }, | ||
265 | + ); | ||
242 | }, | 266 | }, |
243 | onError: (code, msg) { | 267 | onError: (code, msg) { |
244 | isPublishing = false; | 268 | isPublishing = false; |
... | @@ -246,14 +270,6 @@ class _PoemPublishState extends State<PoemPublish> { | ... | @@ -246,14 +270,6 @@ class _PoemPublishState extends State<PoemPublish> { |
246 | }, | 270 | }, |
247 | ); | 271 | ); |
248 | }); | 272 | }); |
249 | - | ||
250 | - // TODO 等待套入正式接口发布临境 | ||
251 | - // await Future.delayed(const Duration(seconds: 2), () { | ||
252 | - // NavigatorUtils.push( | ||
253 | - // context, | ||
254 | - // '${PoemRouter.poemCompletePage}?id=100', | ||
255 | - // ); | ||
256 | - // }); | ||
257 | } | 273 | } |
258 | 274 | ||
259 | Future<bool> _isExit() async { | 275 | Future<bool> _isExit() async { | ... | ... |
-
Please register or login to post a comment