Reason Pun

增加了一言搜索页面

...@@ -95,18 +95,18 @@ class JsonConvert { ...@@ -95,18 +95,18 @@ class JsonConvert {
95 } 95 }
96 96
97 //list is returned by type 97 //list is returned by type
98 - static M? _getListChildType<M>(List<dynamic> data) { 98 + static M? _getListChildType<M>(List<Map<String, dynamic>> data) {
99 if(<UserEntity>[] is M){ 99 if(<UserEntity>[] is M){
100 - return data.map<UserEntity>((e) => UserEntity.fromJson(e)).toList() as M; 100 + return data.map<UserEntity>((Map<String, dynamic> e) => UserEntity.fromJson(e)).toList() as M;
101 } 101 }
102 if(<CategoryItemEntity>[] is M){ 102 if(<CategoryItemEntity>[] is M){
103 - return data.map<CategoryItemEntity>((e) => CategoryItemEntity.fromJson(e)).toList() as M; 103 + return data.map<CategoryItemEntity>((Map<String, dynamic> e) => CategoryItemEntity.fromJson(e)).toList() as M;
104 } 104 }
105 if(<FriendEntity>[] is M){ 105 if(<FriendEntity>[] is M){
106 - return data.map<FriendEntity>((e) => FriendEntity.fromJson(e)).toList() as M; 106 + return data.map<FriendEntity>((Map<String, dynamic> e) => FriendEntity.fromJson(e)).toList() as M;
107 } 107 }
108 if(<FriendData>[] is M){ 108 if(<FriendData>[] is M){
109 - return data.map<FriendData>((e) => FriendData.fromJson(e)).toList() as M; 109 + return data.map<FriendData>((Map<String, dynamic> e) => FriendData.fromJson(e)).toList() as M;
110 } 110 }
111 111
112 print("${M.toString()} not found"); 112 print("${M.toString()} not found");
...@@ -117,9 +117,8 @@ class JsonConvert { ...@@ -117,9 +117,8 @@ class JsonConvert {
117 static M? fromJsonAsT<M>(dynamic json) { 117 static M? fromJsonAsT<M>(dynamic json) {
118 if(json == null){ 118 if(json == null){
119 return null; 119 return null;
120 - } 120 + } if (json is List) {
121 - if (json is List) { 121 + return _getListChildType<M>(json.map((e) => e as Map<String, dynamic>).toList());
122 - return _getListChildType<M>(json);
123 } else { 122 } else {
124 return _fromJsonSingle<M>(json as Map<String, dynamic>); 123 return _fromJsonSingle<M>(json as Map<String, dynamic>);
125 } 124 }
......
1 +import 'package:one_poem/generated/json/base/json_convert_content.dart';
2 +import 'package:one_poem/poem/models/search_entity.dart';
3 +
4 +SearchEntity $SearchEntityFromJson(Map<String, dynamic> json) {
5 + final SearchEntity searchEntity = SearchEntity();
6 + final int? totalCount = jsonConvert.convert<int>(json['total_count']);
7 + if (totalCount != null) {
8 + searchEntity.totalCount = totalCount;
9 + }
10 + final bool? incompleteResults =
11 + jsonConvert.convert<bool>(json['incomplete_results']);
12 + if (incompleteResults != null) {
13 + searchEntity.incompleteResults = incompleteResults;
14 + }
15 + final List<SearchItems>? items =
16 + jsonConvert.convertListNotNull<SearchItems>(json['items']);
17 + if (items != null) {
18 + searchEntity.items = items;
19 + }
20 + return searchEntity;
21 +}
22 +
23 +Map<String, dynamic> $SearchEntityToJson(SearchEntity entity) {
24 + final Map<String, dynamic> data = <String, dynamic>{};
25 + data['total_count'] = entity.totalCount;
26 + data['incomplete_results'] = entity.incompleteResults;
27 + data['items'] = entity.items?.map((v) => v.toJson()).toList();
28 + return data;
29 +}
30 +
31 +SearchItems $SearchItemsFromJson(Map<String, dynamic> json) {
32 + final SearchItems searchItems = SearchItems();
33 + final int? id = jsonConvert.convert<int>(json['id']);
34 + if (id != null) {
35 + searchItems.id = id;
36 + }
37 + final String? nodeId = jsonConvert.convert<String>(json['node_id']);
38 + if (nodeId != null) {
39 + searchItems.nodeId = nodeId;
40 + }
41 + final String? name = jsonConvert.convert<String>(json['name']);
42 + if (name != null) {
43 + searchItems.name = name;
44 + }
45 + final String? fullName = jsonConvert.convert<String>(json['full_name']);
46 + if (fullName != null) {
47 + searchItems.fullName = fullName;
48 + }
49 + final bool? private = jsonConvert.convert<bool>(json['private']);
50 + if (private != null) {
51 + searchItems.private = private;
52 + }
53 + final SearchItemsOwner? owner =
54 + jsonConvert.convert<SearchItemsOwner>(json['owner']);
55 + if (owner != null) {
56 + searchItems.owner = owner;
57 + }
58 + final String? htmlUrl = jsonConvert.convert<String>(json['html_url']);
59 + if (htmlUrl != null) {
60 + searchItems.htmlUrl = htmlUrl;
61 + }
62 + final String? description = jsonConvert.convert<String>(json['description']);
63 + if (description != null) {
64 + searchItems.description = description;
65 + }
66 + final bool? fork = jsonConvert.convert<bool>(json['fork']);
67 + if (fork != null) {
68 + searchItems.fork = fork;
69 + }
70 + final String? url = jsonConvert.convert<String>(json['url']);
71 + if (url != null) {
72 + searchItems.url = url;
73 + }
74 + final String? forksUrl = jsonConvert.convert<String>(json['forks_url']);
75 + if (forksUrl != null) {
76 + searchItems.forksUrl = forksUrl;
77 + }
78 + final String? keysUrl = jsonConvert.convert<String>(json['keys_url']);
79 + if (keysUrl != null) {
80 + searchItems.keysUrl = keysUrl;
81 + }
82 + final String? collaboratorsUrl =
83 + jsonConvert.convert<String>(json['collaborators_url']);
84 + if (collaboratorsUrl != null) {
85 + searchItems.collaboratorsUrl = collaboratorsUrl;
86 + }
87 + final String? teamsUrl = jsonConvert.convert<String>(json['teams_url']);
88 + if (teamsUrl != null) {
89 + searchItems.teamsUrl = teamsUrl;
90 + }
91 + final String? hooksUrl = jsonConvert.convert<String>(json['hooks_url']);
92 + if (hooksUrl != null) {
93 + searchItems.hooksUrl = hooksUrl;
94 + }
95 + final String? issueEventsUrl =
96 + jsonConvert.convert<String>(json['issue_events_url']);
97 + if (issueEventsUrl != null) {
98 + searchItems.issueEventsUrl = issueEventsUrl;
99 + }
100 + final String? eventsUrl = jsonConvert.convert<String>(json['events_url']);
101 + if (eventsUrl != null) {
102 + searchItems.eventsUrl = eventsUrl;
103 + }
104 + final String? assigneesUrl =
105 + jsonConvert.convert<String>(json['assignees_url']);
106 + if (assigneesUrl != null) {
107 + searchItems.assigneesUrl = assigneesUrl;
108 + }
109 + final String? branchesUrl = jsonConvert.convert<String>(json['branches_url']);
110 + if (branchesUrl != null) {
111 + searchItems.branchesUrl = branchesUrl;
112 + }
113 + final String? tagsUrl = jsonConvert.convert<String>(json['tags_url']);
114 + if (tagsUrl != null) {
115 + searchItems.tagsUrl = tagsUrl;
116 + }
117 + final String? blobsUrl = jsonConvert.convert<String>(json['blobs_url']);
118 + if (blobsUrl != null) {
119 + searchItems.blobsUrl = blobsUrl;
120 + }
121 + final String? gitTagsUrl = jsonConvert.convert<String>(json['git_tags_url']);
122 + if (gitTagsUrl != null) {
123 + searchItems.gitTagsUrl = gitTagsUrl;
124 + }
125 + final String? gitRefsUrl = jsonConvert.convert<String>(json['git_refs_url']);
126 + if (gitRefsUrl != null) {
127 + searchItems.gitRefsUrl = gitRefsUrl;
128 + }
129 + final String? treesUrl = jsonConvert.convert<String>(json['trees_url']);
130 + if (treesUrl != null) {
131 + searchItems.treesUrl = treesUrl;
132 + }
133 + final String? statusesUrl = jsonConvert.convert<String>(json['statuses_url']);
134 + if (statusesUrl != null) {
135 + searchItems.statusesUrl = statusesUrl;
136 + }
137 + final String? languagesUrl =
138 + jsonConvert.convert<String>(json['languages_url']);
139 + if (languagesUrl != null) {
140 + searchItems.languagesUrl = languagesUrl;
141 + }
142 + final String? stargazersUrl =
143 + jsonConvert.convert<String>(json['stargazers_url']);
144 + if (stargazersUrl != null) {
145 + searchItems.stargazersUrl = stargazersUrl;
146 + }
147 + final String? contributorsUrl =
148 + jsonConvert.convert<String>(json['contributors_url']);
149 + if (contributorsUrl != null) {
150 + searchItems.contributorsUrl = contributorsUrl;
151 + }
152 + final String? subscribersUrl =
153 + jsonConvert.convert<String>(json['subscribers_url']);
154 + if (subscribersUrl != null) {
155 + searchItems.subscribersUrl = subscribersUrl;
156 + }
157 + final String? subscriptionUrl =
158 + jsonConvert.convert<String>(json['subscription_url']);
159 + if (subscriptionUrl != null) {
160 + searchItems.subscriptionUrl = subscriptionUrl;
161 + }
162 + final String? commitsUrl = jsonConvert.convert<String>(json['commits_url']);
163 + if (commitsUrl != null) {
164 + searchItems.commitsUrl = commitsUrl;
165 + }
166 + final String? gitCommitsUrl =
167 + jsonConvert.convert<String>(json['git_commits_url']);
168 + if (gitCommitsUrl != null) {
169 + searchItems.gitCommitsUrl = gitCommitsUrl;
170 + }
171 + final String? commentsUrl = jsonConvert.convert<String>(json['comments_url']);
172 + if (commentsUrl != null) {
173 + searchItems.commentsUrl = commentsUrl;
174 + }
175 + final String? issueCommentUrl =
176 + jsonConvert.convert<String>(json['issue_comment_url']);
177 + if (issueCommentUrl != null) {
178 + searchItems.issueCommentUrl = issueCommentUrl;
179 + }
180 + final String? contentsUrl = jsonConvert.convert<String>(json['contents_url']);
181 + if (contentsUrl != null) {
182 + searchItems.contentsUrl = contentsUrl;
183 + }
184 + final String? compareUrl = jsonConvert.convert<String>(json['compare_url']);
185 + if (compareUrl != null) {
186 + searchItems.compareUrl = compareUrl;
187 + }
188 + final String? mergesUrl = jsonConvert.convert<String>(json['merges_url']);
189 + if (mergesUrl != null) {
190 + searchItems.mergesUrl = mergesUrl;
191 + }
192 + final String? archiveUrl = jsonConvert.convert<String>(json['archive_url']);
193 + if (archiveUrl != null) {
194 + searchItems.archiveUrl = archiveUrl;
195 + }
196 + final String? downloadsUrl =
197 + jsonConvert.convert<String>(json['downloads_url']);
198 + if (downloadsUrl != null) {
199 + searchItems.downloadsUrl = downloadsUrl;
200 + }
201 + final String? issuesUrl = jsonConvert.convert<String>(json['issues_url']);
202 + if (issuesUrl != null) {
203 + searchItems.issuesUrl = issuesUrl;
204 + }
205 + final String? pullsUrl = jsonConvert.convert<String>(json['pulls_url']);
206 + if (pullsUrl != null) {
207 + searchItems.pullsUrl = pullsUrl;
208 + }
209 + final String? milestonesUrl =
210 + jsonConvert.convert<String>(json['milestones_url']);
211 + if (milestonesUrl != null) {
212 + searchItems.milestonesUrl = milestonesUrl;
213 + }
214 + final String? notificationsUrl =
215 + jsonConvert.convert<String>(json['notifications_url']);
216 + if (notificationsUrl != null) {
217 + searchItems.notificationsUrl = notificationsUrl;
218 + }
219 + final String? labelsUrl = jsonConvert.convert<String>(json['labels_url']);
220 + if (labelsUrl != null) {
221 + searchItems.labelsUrl = labelsUrl;
222 + }
223 + final String? releasesUrl = jsonConvert.convert<String>(json['releases_url']);
224 + if (releasesUrl != null) {
225 + searchItems.releasesUrl = releasesUrl;
226 + }
227 + final String? deploymentsUrl =
228 + jsonConvert.convert<String>(json['deployments_url']);
229 + if (deploymentsUrl != null) {
230 + searchItems.deploymentsUrl = deploymentsUrl;
231 + }
232 + final String? createdAt = jsonConvert.convert<String>(json['created_at']);
233 + if (createdAt != null) {
234 + searchItems.createdAt = createdAt;
235 + }
236 + final String? updatedAt = jsonConvert.convert<String>(json['updated_at']);
237 + if (updatedAt != null) {
238 + searchItems.updatedAt = updatedAt;
239 + }
240 + final String? pushedAt = jsonConvert.convert<String>(json['pushed_at']);
241 + if (pushedAt != null) {
242 + searchItems.pushedAt = pushedAt;
243 + }
244 + final String? gitUrl = jsonConvert.convert<String>(json['git_url']);
245 + if (gitUrl != null) {
246 + searchItems.gitUrl = gitUrl;
247 + }
248 + final String? sshUrl = jsonConvert.convert<String>(json['ssh_url']);
249 + if (sshUrl != null) {
250 + searchItems.sshUrl = sshUrl;
251 + }
252 + final String? cloneUrl = jsonConvert.convert<String>(json['clone_url']);
253 + if (cloneUrl != null) {
254 + searchItems.cloneUrl = cloneUrl;
255 + }
256 + final String? svnUrl = jsonConvert.convert<String>(json['svn_url']);
257 + if (svnUrl != null) {
258 + searchItems.svnUrl = svnUrl;
259 + }
260 + final String? homepage = jsonConvert.convert<String>(json['homepage']);
261 + if (homepage != null) {
262 + searchItems.homepage = homepage;
263 + }
264 + final int? size = jsonConvert.convert<int>(json['size']);
265 + if (size != null) {
266 + searchItems.size = size;
267 + }
268 + final int? stargazersCount =
269 + jsonConvert.convert<int>(json['stargazers_count']);
270 + if (stargazersCount != null) {
271 + searchItems.stargazersCount = stargazersCount;
272 + }
273 + final int? watchersCount = jsonConvert.convert<int>(json['watchers_count']);
274 + if (watchersCount != null) {
275 + searchItems.watchersCount = watchersCount;
276 + }
277 + final String? language = jsonConvert.convert<String>(json['language']);
278 + if (language != null) {
279 + searchItems.language = language;
280 + }
281 + final bool? hasIssues = jsonConvert.convert<bool>(json['has_issues']);
282 + if (hasIssues != null) {
283 + searchItems.hasIssues = hasIssues;
284 + }
285 + final bool? hasProjects = jsonConvert.convert<bool>(json['has_projects']);
286 + if (hasProjects != null) {
287 + searchItems.hasProjects = hasProjects;
288 + }
289 + final bool? hasDownloads = jsonConvert.convert<bool>(json['has_downloads']);
290 + if (hasDownloads != null) {
291 + searchItems.hasDownloads = hasDownloads;
292 + }
293 + final bool? hasWiki = jsonConvert.convert<bool>(json['has_wiki']);
294 + if (hasWiki != null) {
295 + searchItems.hasWiki = hasWiki;
296 + }
297 + final bool? hasPages = jsonConvert.convert<bool>(json['has_pages']);
298 + if (hasPages != null) {
299 + searchItems.hasPages = hasPages;
300 + }
301 + final int? forksCount = jsonConvert.convert<int>(json['forks_count']);
302 + if (forksCount != null) {
303 + searchItems.forksCount = forksCount;
304 + }
305 + final bool? archived = jsonConvert.convert<bool>(json['archived']);
306 + if (archived != null) {
307 + searchItems.archived = archived;
308 + }
309 + final bool? disabled = jsonConvert.convert<bool>(json['disabled']);
310 + if (disabled != null) {
311 + searchItems.disabled = disabled;
312 + }
313 + final int? openIssuesCount =
314 + jsonConvert.convert<int>(json['open_issues_count']);
315 + if (openIssuesCount != null) {
316 + searchItems.openIssuesCount = openIssuesCount;
317 + }
318 + final SearchItemsLicense? license =
319 + jsonConvert.convert<SearchItemsLicense>(json['license']);
320 + if (license != null) {
321 + searchItems.license = license;
322 + }
323 + final int? forks = jsonConvert.convert<int>(json['forks']);
324 + if (forks != null) {
325 + searchItems.forks = forks;
326 + }
327 + final int? openIssues = jsonConvert.convert<int>(json['open_issues']);
328 + if (openIssues != null) {
329 + searchItems.openIssues = openIssues;
330 + }
331 + final int? watchers = jsonConvert.convert<int>(json['watchers']);
332 + if (watchers != null) {
333 + searchItems.watchers = watchers;
334 + }
335 + final String? defaultBranch =
336 + jsonConvert.convert<String>(json['default_branch']);
337 + if (defaultBranch != null) {
338 + searchItems.defaultBranch = defaultBranch;
339 + }
340 + final double? score = jsonConvert.convert<double>(json['score']);
341 + if (score != null) {
342 + searchItems.score = score;
343 + }
344 + return searchItems;
345 +}
346 +
347 +Map<String, dynamic> $SearchItemsToJson(SearchItems entity) {
348 + final Map<String, dynamic> data = <String, dynamic>{};
349 + data['id'] = entity.id;
350 + data['node_id'] = entity.nodeId;
351 + data['name'] = entity.name;
352 + data['full_name'] = entity.fullName;
353 + data['private'] = entity.private;
354 + data['owner'] = entity.owner?.toJson();
355 + data['html_url'] = entity.htmlUrl;
356 + data['description'] = entity.description;
357 + data['fork'] = entity.fork;
358 + data['url'] = entity.url;
359 + data['forks_url'] = entity.forksUrl;
360 + data['keys_url'] = entity.keysUrl;
361 + data['collaborators_url'] = entity.collaboratorsUrl;
362 + data['teams_url'] = entity.teamsUrl;
363 + data['hooks_url'] = entity.hooksUrl;
364 + data['issue_events_url'] = entity.issueEventsUrl;
365 + data['events_url'] = entity.eventsUrl;
366 + data['assignees_url'] = entity.assigneesUrl;
367 + data['branches_url'] = entity.branchesUrl;
368 + data['tags_url'] = entity.tagsUrl;
369 + data['blobs_url'] = entity.blobsUrl;
370 + data['git_tags_url'] = entity.gitTagsUrl;
371 + data['git_refs_url'] = entity.gitRefsUrl;
372 + data['trees_url'] = entity.treesUrl;
373 + data['statuses_url'] = entity.statusesUrl;
374 + data['languages_url'] = entity.languagesUrl;
375 + data['stargazers_url'] = entity.stargazersUrl;
376 + data['contributors_url'] = entity.contributorsUrl;
377 + data['subscribers_url'] = entity.subscribersUrl;
378 + data['subscription_url'] = entity.subscriptionUrl;
379 + data['commits_url'] = entity.commitsUrl;
380 + data['git_commits_url'] = entity.gitCommitsUrl;
381 + data['comments_url'] = entity.commentsUrl;
382 + data['issue_comment_url'] = entity.issueCommentUrl;
383 + data['contents_url'] = entity.contentsUrl;
384 + data['compare_url'] = entity.compareUrl;
385 + data['merges_url'] = entity.mergesUrl;
386 + data['archive_url'] = entity.archiveUrl;
387 + data['downloads_url'] = entity.downloadsUrl;
388 + data['issues_url'] = entity.issuesUrl;
389 + data['pulls_url'] = entity.pullsUrl;
390 + data['milestones_url'] = entity.milestonesUrl;
391 + data['notifications_url'] = entity.notificationsUrl;
392 + data['labels_url'] = entity.labelsUrl;
393 + data['releases_url'] = entity.releasesUrl;
394 + data['deployments_url'] = entity.deploymentsUrl;
395 + data['created_at'] = entity.createdAt;
396 + data['updated_at'] = entity.updatedAt;
397 + data['pushed_at'] = entity.pushedAt;
398 + data['git_url'] = entity.gitUrl;
399 + data['ssh_url'] = entity.sshUrl;
400 + data['clone_url'] = entity.cloneUrl;
401 + data['svn_url'] = entity.svnUrl;
402 + data['homepage'] = entity.homepage;
403 + data['size'] = entity.size;
404 + data['stargazers_count'] = entity.stargazersCount;
405 + data['watchers_count'] = entity.watchersCount;
406 + data['language'] = entity.language;
407 + data['has_issues'] = entity.hasIssues;
408 + data['has_projects'] = entity.hasProjects;
409 + data['has_downloads'] = entity.hasDownloads;
410 + data['has_wiki'] = entity.hasWiki;
411 + data['has_pages'] = entity.hasPages;
412 + data['forks_count'] = entity.forksCount;
413 + data['archived'] = entity.archived;
414 + data['disabled'] = entity.disabled;
415 + data['open_issues_count'] = entity.openIssuesCount;
416 + data['license'] = entity.license?.toJson();
417 + data['forks'] = entity.forks;
418 + data['open_issues'] = entity.openIssues;
419 + data['watchers'] = entity.watchers;
420 + data['default_branch'] = entity.defaultBranch;
421 + data['score'] = entity.score;
422 + return data;
423 +}
424 +
425 +SearchItemsOwner $SearchItemsOwnerFromJson(Map<String, dynamic> json) {
426 + final SearchItemsOwner searchItemsOwner = SearchItemsOwner();
427 + final String? login = jsonConvert.convert<String>(json['login']);
428 + if (login != null) {
429 + searchItemsOwner.login = login;
430 + }
431 + final int? id = jsonConvert.convert<int>(json['id']);
432 + if (id != null) {
433 + searchItemsOwner.id = id;
434 + }
435 + final String? nodeId = jsonConvert.convert<String>(json['node_id']);
436 + if (nodeId != null) {
437 + searchItemsOwner.nodeId = nodeId;
438 + }
439 + final String? avatarUrl = jsonConvert.convert<String>(json['avatar_url']);
440 + if (avatarUrl != null) {
441 + searchItemsOwner.avatarUrl = avatarUrl;
442 + }
443 + final String? gravatarId = jsonConvert.convert<String>(json['gravatar_id']);
444 + if (gravatarId != null) {
445 + searchItemsOwner.gravatarId = gravatarId;
446 + }
447 + final String? url = jsonConvert.convert<String>(json['url']);
448 + if (url != null) {
449 + searchItemsOwner.url = url;
450 + }
451 + final String? htmlUrl = jsonConvert.convert<String>(json['html_url']);
452 + if (htmlUrl != null) {
453 + searchItemsOwner.htmlUrl = htmlUrl;
454 + }
455 + final String? followersUrl =
456 + jsonConvert.convert<String>(json['followers_url']);
457 + if (followersUrl != null) {
458 + searchItemsOwner.followersUrl = followersUrl;
459 + }
460 + final String? followingUrl =
461 + jsonConvert.convert<String>(json['following_url']);
462 + if (followingUrl != null) {
463 + searchItemsOwner.followingUrl = followingUrl;
464 + }
465 + final String? gistsUrl = jsonConvert.convert<String>(json['gists_url']);
466 + if (gistsUrl != null) {
467 + searchItemsOwner.gistsUrl = gistsUrl;
468 + }
469 + final String? starredUrl = jsonConvert.convert<String>(json['starred_url']);
470 + if (starredUrl != null) {
471 + searchItemsOwner.starredUrl = starredUrl;
472 + }
473 + final String? subscriptionsUrl =
474 + jsonConvert.convert<String>(json['subscriptions_url']);
475 + if (subscriptionsUrl != null) {
476 + searchItemsOwner.subscriptionsUrl = subscriptionsUrl;
477 + }
478 + final String? organizationsUrl =
479 + jsonConvert.convert<String>(json['organizations_url']);
480 + if (organizationsUrl != null) {
481 + searchItemsOwner.organizationsUrl = organizationsUrl;
482 + }
483 + final String? reposUrl = jsonConvert.convert<String>(json['repos_url']);
484 + if (reposUrl != null) {
485 + searchItemsOwner.reposUrl = reposUrl;
486 + }
487 + final String? eventsUrl = jsonConvert.convert<String>(json['events_url']);
488 + if (eventsUrl != null) {
489 + searchItemsOwner.eventsUrl = eventsUrl;
490 + }
491 + final String? receivedEventsUrl =
492 + jsonConvert.convert<String>(json['received_events_url']);
493 + if (receivedEventsUrl != null) {
494 + searchItemsOwner.receivedEventsUrl = receivedEventsUrl;
495 + }
496 + final String? type = jsonConvert.convert<String>(json['type']);
497 + if (type != null) {
498 + searchItemsOwner.type = type;
499 + }
500 + final bool? siteAdmin = jsonConvert.convert<bool>(json['site_admin']);
501 + if (siteAdmin != null) {
502 + searchItemsOwner.siteAdmin = siteAdmin;
503 + }
504 + return searchItemsOwner;
505 +}
506 +
507 +Map<String, dynamic> $SearchItemsOwnerToJson(SearchItemsOwner entity) {
508 + final Map<String, dynamic> data = <String, dynamic>{};
509 + data['login'] = entity.login;
510 + data['id'] = entity.id;
511 + data['node_id'] = entity.nodeId;
512 + data['avatar_url'] = entity.avatarUrl;
513 + data['gravatar_id'] = entity.gravatarId;
514 + data['url'] = entity.url;
515 + data['html_url'] = entity.htmlUrl;
516 + data['followers_url'] = entity.followersUrl;
517 + data['following_url'] = entity.followingUrl;
518 + data['gists_url'] = entity.gistsUrl;
519 + data['starred_url'] = entity.starredUrl;
520 + data['subscriptions_url'] = entity.subscriptionsUrl;
521 + data['organizations_url'] = entity.organizationsUrl;
522 + data['repos_url'] = entity.reposUrl;
523 + data['events_url'] = entity.eventsUrl;
524 + data['received_events_url'] = entity.receivedEventsUrl;
525 + data['type'] = entity.type;
526 + data['site_admin'] = entity.siteAdmin;
527 + return data;
528 +}
529 +
530 +SearchItemsLicense $SearchItemsLicenseFromJson(Map<String, dynamic> json) {
531 + final SearchItemsLicense searchItemsLicense = SearchItemsLicense();
532 + final String? key = jsonConvert.convert<String>(json['key']);
533 + if (key != null) {
534 + searchItemsLicense.key = key;
535 + }
536 + final String? name = jsonConvert.convert<String>(json['name']);
537 + if (name != null) {
538 + searchItemsLicense.name = name;
539 + }
540 + final String? spdxId = jsonConvert.convert<String>(json['spdx_id']);
541 + if (spdxId != null) {
542 + searchItemsLicense.spdxId = spdxId;
543 + }
544 + final String? url = jsonConvert.convert<String>(json['url']);
545 + if (url != null) {
546 + searchItemsLicense.url = url;
547 + }
548 + final String? nodeId = jsonConvert.convert<String>(json['node_id']);
549 + if (nodeId != null) {
550 + searchItemsLicense.nodeId = nodeId;
551 + }
552 + return searchItemsLicense;
553 +}
554 +
555 +Map<String, dynamic> $SearchItemsLicenseToJson(SearchItemsLicense entity) {
556 + final Map<String, dynamic> data = <String, dynamic>{};
557 + data['key'] = entity.key;
558 + data['name'] = entity.name;
559 + data['spdx_id'] = entity.spdxId;
560 + data['url'] = entity.url;
561 + data['node_id'] = entity.nodeId;
562 + return data;
563 +}
1 -
2 -
3 import 'base_page.dart'; 1 import 'base_page.dart';
4 import 'base_page_presenter.dart'; 2 import 'base_page_presenter.dart';
5 import 'base_presenter.dart'; 3 import 'base_presenter.dart';
6 4
7 /// 管理多个Presenter,实现复用。 5 /// 管理多个Presenter,实现复用。
8 class PowerPresenter<IMvpView> extends BasePresenter { 6 class PowerPresenter<IMvpView> extends BasePresenter {
9 -
10 PowerPresenter(BasePageMixin state) { 7 PowerPresenter(BasePageMixin state) {
11 _state = state; 8 _state = state;
12 } 9 }
...@@ -43,10 +40,10 @@ class PowerPresenter<IMvpView> extends BasePresenter { ...@@ -43,10 +40,10 @@ class PowerPresenter<IMvpView> extends BasePresenter {
43 40
44 @override 41 @override
45 void didUpdateWidgets<W>(W oldWidget) { 42 void didUpdateWidgets<W>(W oldWidget) {
46 -
47 void _didUpdateWidgets(BasePagePresenter presenter) { 43 void _didUpdateWidgets(BasePagePresenter presenter) {
48 presenter.didUpdateWidgets<W>(oldWidget); 44 presenter.didUpdateWidgets<W>(oldWidget);
49 } 45 }
46 +
50 _presenters.forEach(_didUpdateWidgets); 47 _presenters.forEach(_didUpdateWidgets);
51 } 48 }
52 49
...@@ -67,5 +64,4 @@ class PowerPresenter<IMvpView> extends BasePresenter { ...@@ -67,5 +64,4 @@ class PowerPresenter<IMvpView> extends BasePresenter {
67 void _initState(BasePagePresenter presenter) { 64 void _initState(BasePagePresenter presenter) {
68 presenter.initState(); 65 presenter.initState();
69 } 66 }
70 -
71 } 67 }
......
1 +import 'package:one_poem/mvp/mvps.dart';
2 +import 'package:one_poem/poem/models/search_entity.dart';
3 +import 'package:one_poem/poem/provider/base_list_provider.dart';
4 +
5 +abstract class PoemSearchIMvpView implements IMvpView {
6 + BaseListProvider<SearchItems> get provider;
7 +}
1 +import 'package:one_poem/generated/json/base/json_field.dart';
2 +import 'package:one_poem/generated/json/search_entity.g.dart';
3 +
4 +@JsonSerializable()
5 +class SearchEntity {
6 +
7 + SearchEntity();
8 +
9 + factory SearchEntity.fromJson(Map<String, dynamic> json) => $SearchEntityFromJson(json);
10 +
11 + Map<String, dynamic> toJson() => $SearchEntityToJson(this);
12 +
13 + @JSONField(name: 'total_count')
14 + int? totalCount;
15 + @JSONField(name: 'incomplete_results')
16 + bool? incompleteResults;
17 + List<SearchItems>? items;
18 +}
19 +
20 +@JsonSerializable()
21 +class SearchItems {
22 +
23 + SearchItems();
24 +
25 + factory SearchItems.fromJson(Map<String, dynamic> json) => $SearchItemsFromJson(json);
26 +
27 + Map<String, dynamic> toJson() => $SearchItemsToJson(this);
28 +
29 + int? id;
30 + @JSONField(name: 'node_id')
31 + String? nodeId;
32 + String? name;
33 + @JSONField(name: 'full_name')
34 + String? fullName;
35 + bool? private;
36 + SearchItemsOwner? owner;
37 + @JSONField(name: 'html_url')
38 + String? htmlUrl;
39 + String? description;
40 + bool? fork;
41 + String? url;
42 + @JSONField(name: 'forks_url')
43 + String? forksUrl;
44 + @JSONField(name: 'keys_url')
45 + String? keysUrl;
46 + @JSONField(name: 'collaborators_url')
47 + String? collaboratorsUrl;
48 + @JSONField(name: 'teams_url')
49 + String? teamsUrl;
50 + @JSONField(name: 'hooks_url')
51 + String? hooksUrl;
52 + @JSONField(name: 'issue_events_url')
53 + String? issueEventsUrl;
54 + @JSONField(name: 'events_url')
55 + String? eventsUrl;
56 + @JSONField(name: 'assignees_url')
57 + String? assigneesUrl;
58 + @JSONField(name: 'branches_url')
59 + String? branchesUrl;
60 + @JSONField(name: 'tags_url')
61 + String? tagsUrl;
62 + @JSONField(name: 'blobs_url')
63 + String? blobsUrl;
64 + @JSONField(name: 'git_tags_url')
65 + String? gitTagsUrl;
66 + @JSONField(name: 'git_refs_url')
67 + String? gitRefsUrl;
68 + @JSONField(name: 'trees_url')
69 + String? treesUrl;
70 + @JSONField(name: 'statuses_url')
71 + String? statusesUrl;
72 + @JSONField(name: 'languages_url')
73 + String? languagesUrl;
74 + @JSONField(name: 'stargazers_url')
75 + String? stargazersUrl;
76 + @JSONField(name: 'contributors_url')
77 + String? contributorsUrl;
78 + @JSONField(name: 'subscribers_url')
79 + String? subscribersUrl;
80 + @JSONField(name: 'subscription_url')
81 + String? subscriptionUrl;
82 + @JSONField(name: 'commits_url')
83 + String? commitsUrl;
84 + @JSONField(name: 'git_commits_url')
85 + String? gitCommitsUrl;
86 + @JSONField(name: 'comments_url')
87 + String? commentsUrl;
88 + @JSONField(name: 'issue_comment_url')
89 + String? issueCommentUrl;
90 + @JSONField(name: 'contents_url')
91 + String? contentsUrl;
92 + @JSONField(name: 'compare_url')
93 + String? compareUrl;
94 + @JSONField(name: 'merges_url')
95 + String? mergesUrl;
96 + @JSONField(name: 'archive_url')
97 + String? archiveUrl;
98 + @JSONField(name: 'downloads_url')
99 + String? downloadsUrl;
100 + @JSONField(name: 'issues_url')
101 + String? issuesUrl;
102 + @JSONField(name: 'pulls_url')
103 + String? pullsUrl;
104 + @JSONField(name: 'milestones_url')
105 + String? milestonesUrl;
106 + @JSONField(name: 'notifications_url')
107 + String? notificationsUrl;
108 + @JSONField(name: 'labels_url')
109 + String? labelsUrl;
110 + @JSONField(name: 'releases_url')
111 + String? releasesUrl;
112 + @JSONField(name: 'deployments_url')
113 + String? deploymentsUrl;
114 + @JSONField(name: 'created_at')
115 + String? createdAt;
116 + @JSONField(name: 'updated_at')
117 + String? updatedAt;
118 + @JSONField(name: 'pushed_at')
119 + String? pushedAt;
120 + @JSONField(name: 'git_url')
121 + String? gitUrl;
122 + @JSONField(name: 'ssh_url')
123 + String? sshUrl;
124 + @JSONField(name: 'clone_url')
125 + String? cloneUrl;
126 + @JSONField(name: 'svn_url')
127 + String? svnUrl;
128 + String? homepage;
129 + int? size;
130 + @JSONField(name: 'stargazers_count')
131 + int? stargazersCount;
132 + @JSONField(name: 'watchers_count')
133 + int? watchersCount;
134 + String? language;
135 + @JSONField(name: 'has_issues')
136 + bool? hasIssues;
137 + @JSONField(name: 'has_projects')
138 + bool? hasProjects;
139 + @JSONField(name: 'has_downloads')
140 + bool? hasDownloads;
141 + @JSONField(name: 'has_wiki')
142 + bool? hasWiki;
143 + @JSONField(name: 'has_pages')
144 + bool? hasPages;
145 + @JSONField(name: 'forks_count')
146 + int? forksCount;
147 + bool? archived;
148 + bool? disabled;
149 + @JSONField(name: 'open_issues_count')
150 + int? openIssuesCount;
151 + SearchItemsLicense? license;
152 + int? forks;
153 + @JSONField(name: 'open_issues')
154 + int? openIssues;
155 + int? watchers;
156 + @JSONField(name: 'default_branch')
157 + String? defaultBranch;
158 + double? score;
159 +}
160 +
161 +@JsonSerializable()
162 +class SearchItemsOwner {
163 +
164 + SearchItemsOwner();
165 +
166 + factory SearchItemsOwner.fromJson(Map<String, dynamic> json) => $SearchItemsOwnerFromJson(json);
167 +
168 + Map<String, dynamic> toJson() => $SearchItemsOwnerToJson(this);
169 +
170 + String? login;
171 + int? id;
172 + @JSONField(name: 'node_id')
173 + String? nodeId;
174 + @JSONField(name: 'avatar_url')
175 + String? avatarUrl;
176 + @JSONField(name: 'gravatar_id')
177 + String? gravatarId;
178 + String? url;
179 + @JSONField(name: 'html_url')
180 + String? htmlUrl;
181 + @JSONField(name: 'followers_url')
182 + String? followersUrl;
183 + @JSONField(name: 'following_url')
184 + String? followingUrl;
185 + @JSONField(name: 'gists_url')
186 + String? gistsUrl;
187 + @JSONField(name: 'starred_url')
188 + String? starredUrl;
189 + @JSONField(name: 'subscriptions_url')
190 + String? subscriptionsUrl;
191 + @JSONField(name: 'organizations_url')
192 + String? organizationsUrl;
193 + @JSONField(name: 'repos_url')
194 + String? reposUrl;
195 + @JSONField(name: 'events_url')
196 + String? eventsUrl;
197 + @JSONField(name: 'received_events_url')
198 + String? receivedEventsUrl;
199 + String? type;
200 + @JSONField(name: 'site_admin')
201 + bool? siteAdmin;
202 +}
203 +
204 +@JsonSerializable()
205 +class SearchItemsLicense {
206 +
207 + SearchItemsLicense();
208 +
209 + factory SearchItemsLicense.fromJson(Map<String, dynamic> json) => $SearchItemsLicenseFromJson(json);
210 +
211 + Map<String, dynamic> toJson() => $SearchItemsLicenseToJson(this);
212 +
213 + String? key;
214 + String? name;
215 + @JSONField(name: 'spdx_id')
216 + String? spdxId;
217 + String? url;
218 + @JSONField(name: 'node_id')
219 + String? nodeId;
220 +}
1 -import 'package:flutter/cupertino.dart';
2 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
3 import 'package:one_poem/category/category_router.dart'; 2 import 'package:one_poem/category/category_router.dart';
3 +import 'package:one_poem/poem/poem_router.dart';
4 import 'package:one_poem/routers/fluro_navigator.dart'; 4 import 'package:one_poem/routers/fluro_navigator.dart';
5 import 'package:one_poem/tiktok/controller/tiktok_video_list_controller.dart'; 5 import 'package:one_poem/tiktok/controller/tiktok_video_list_controller.dart';
6 import 'package:one_poem/tiktok/mock/video.dart'; 6 import 'package:one_poem/tiktok/mock/video.dart';
...@@ -134,7 +134,10 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver { ...@@ -134,7 +134,10 @@ class _PoemPageState extends State<PoemPage> with WidgetsBindingObserver {
134 Icons.search, 134 Icons.search,
135 color: Colors.white, 135 color: Colors.white,
136 ), 136 ),
137 - onPressed: () {}, 137 + onPressed: () {
138 + NavigatorUtils.push(context, PoemRouter.poemSearchPage);
139 + _videoListController.currentPlayer.pause();
140 + },
138 ), 141 ),
139 ), 142 ),
140 leftPage: searchPage, 143 leftPage: searchPage,
......
1 +import 'package:flutter/material.dart';
2 +import 'package:one_poem/mvp/base_page.dart';
3 +import 'package:one_poem/mvp/power_presenter.dart';
4 +import 'package:one_poem/poem/iview/poem_search_iview.dart';
5 +import 'package:one_poem/poem/models/search_entity.dart';
6 +import 'package:one_poem/poem/presenter/poem_search_presenter.dart';
7 +import 'package:one_poem/poem/provider/base_list_provider.dart';
8 +import 'package:one_poem/widgets/my_refresh_list.dart';
9 +import 'package:one_poem/widgets/search_bar.dart';
10 +import 'package:one_poem/widgets/state_layout.dart';
11 +import 'package:provider/provider.dart';
12 +
13 +import 'package:one_poem/extension/int_extension.dart';
14 +
15 +class PoemSearchPage extends StatefulWidget {
16 + const PoemSearchPage({Key? key}) : super(key: key);
17 +
18 + @override
19 + _PoemSearchPageState createState() => _PoemSearchPageState();
20 +}
21 +
22 +class _PoemSearchPageState extends State<PoemSearchPage>
23 + with BasePageMixin<PoemSearchPage, PowerPresenter>
24 + implements PoemSearchIMvpView {
25 + @override
26 + BaseListProvider<SearchItems> provider = BaseListProvider<SearchItems>();
27 +
28 + late String _keyword;
29 + int _page = 1;
30 +
31 + @override
32 + void initState() {
33 + provider.stateType = StateType.empty;
34 + super.initState();
35 + }
36 +
37 + @override
38 + Widget build(BuildContext context) {
39 + return ChangeNotifierProvider<BaseListProvider<SearchItems>>(
40 + create: (_) => provider,
41 + child: Scaffold(
42 + appBar: SearchBar(
43 + hintText: '请输入要查询的内容',
44 + onPressed: (text) {
45 + if (text.isEmpty) {
46 + showToast('搜索关键字不能为空!');
47 + return;
48 + }
49 + _keyword = text;
50 + provider.setStateType(StateType.loading);
51 + _page = 1;
52 + _poemSearchPresenter.search(_keyword, _page, true);
53 + },
54 + ),
55 + body:
56 + Consumer<BaseListProvider<SearchItems>>(builder: (_, provider, __) {
57 + return DeerListView(
58 + key: const Key('poem_search_list'),
59 + itemCount: provider.list.length,
60 + stateType: provider.stateType,
61 + onRefresh: _onRefresh,
62 + loadMore: _loadMore,
63 + itemExtent: 50.0,
64 + hasMore: provider.hasMore,
65 + itemBuilder: (_, index) {
66 + return Container(
67 + padding: EdgeInsets.symmetric(horizontal: 16.px),
68 + alignment: Alignment.centerLeft,
69 + child: Text(provider.list[index].name!),
70 + );
71 + },
72 + );
73 + }),
74 + ),
75 + );
76 + }
77 +
78 + Future<void> _onRefresh() async {
79 + _page = 1;
80 + await _poemSearchPresenter.search(_keyword, _page, false);
81 + }
82 +
83 + Future<void> _loadMore() async {
84 + _page++;
85 + await _poemSearchPresenter.search(_keyword, _page, false);
86 + }
87 +
88 + late PoemSearchPresenter _poemSearchPresenter;
89 + @override
90 + PowerPresenter createPresenter() {
91 + final PowerPresenter powerPresenter = PowerPresenter<dynamic>(this);
92 + _poemSearchPresenter = PoemSearchPresenter();
93 + powerPresenter.requestPresenter([_poemSearchPresenter]);
94 + return powerPresenter;
95 + }
96 +}
1 import 'package:fluro/fluro.dart'; 1 import 'package:fluro/fluro.dart';
2 import 'package:one_poem/poem/page/poem_record_audio.dart'; 2 import 'package:one_poem/poem/page/poem_record_audio.dart';
3 +import 'package:one_poem/poem/page/poem_search_page.dart';
3 import 'package:one_poem/routers/i_router.dart'; 4 import 'package:one_poem/routers/i_router.dart';
4 import 'page/poem_complete_page.dart'; 5 import 'page/poem_complete_page.dart';
5 import 'page/poem_detail.dart'; 6 import 'page/poem_detail.dart';
...@@ -16,6 +17,7 @@ class PoemRouter implements IRouterProvider { ...@@ -16,6 +17,7 @@ class PoemRouter implements IRouterProvider {
16 static String poemVideoPlayer = '/poem/video/player'; 17 static String poemVideoPlayer = '/poem/video/player';
17 static String poemPublish = '/poem/publish'; 18 static String poemPublish = '/poem/publish';
18 static String poemCompletePage = '/poem/complete'; 19 static String poemCompletePage = '/poem/complete';
20 + static String poemSearchPage = '/poem/search';
19 21
20 @override 22 @override
21 void initRouter(FluroRouter router) { 23 void initRouter(FluroRouter router) {
...@@ -25,6 +27,7 @@ class PoemRouter implements IRouterProvider { ...@@ -25,6 +27,7 @@ class PoemRouter implements IRouterProvider {
25 handlerFunc: (_, __) => const PoemPage(), 27 handlerFunc: (_, __) => const PoemPage(),
26 ), 28 ),
27 ); 29 );
30 +
28 router.define( 31 router.define(
29 poemDetailPage, 32 poemDetailPage,
30 handler: Handler( 33 handler: Handler(
...@@ -95,5 +98,8 @@ class PoemRouter implements IRouterProvider { ...@@ -95,5 +98,8 @@ class PoemRouter implements IRouterProvider {
95 }, 98 },
96 ), 99 ),
97 ); 100 );
101 +
102 + router.define(poemSearchPage,
103 + handler: Handler(handlerFunc: (_, __) => const PoemSearchPage()));
98 } 104 }
99 } 105 }
......
1 +import 'package:one_poem/mvp/base_page_presenter.dart';
2 +import 'package:one_poem/net/dio_utils.dart';
3 +import 'package:one_poem/net/http_api.dart';
4 +import 'package:one_poem/poem/iview/poem_search_iview.dart';
5 +import 'package:one_poem/poem/models/search_entity.dart';
6 +import 'package:one_poem/widgets/state_layout.dart';
7 +
8 +class PoemSearchPresenter extends BasePagePresenter<PoemSearchIMvpView> {
9 +
10 + Future search(String text, int page, bool isShowDialog) {
11 +
12 + final Map<String, String> params = <String, String>{};
13 + params['q'] = text;
14 + params['page'] = page.toString();
15 + params['l'] = 'Dart';
16 + return requestNetwork<SearchEntity>(Method.get,
17 + url: HttpApi.search,
18 + queryParameters: params,
19 + isShow: isShowDialog,
20 + onSuccess: (data) {
21 + if (data != null && data.items != null) {
22 + /// 一页30条数据,等于30条认为有下一页
23 + /// 具体的处理逻辑根据具体的接口情况处理,这部分可以抽离出来
24 + view.provider.hasMore = data.items!.length == 30;
25 + if (page == 1) {
26 + /// 刷新
27 + view.provider.list.clear();
28 + if (data.items!.isEmpty) {
29 + view.provider.setStateType(StateType.order);
30 + } else {
31 + view.provider.addAll(data.items!);
32 + }
33 + } else {
34 + view.provider.addAll(data.items!);
35 + }
36 + } else {
37 + /// 加载失败
38 + view.provider.hasMore = false;
39 + view.provider.setStateType(StateType.network);
40 + }
41 + },
42 + onError: (_, __) {
43 + /// 加载失败
44 + view.provider.hasMore = false;
45 + view.provider.setStateType(StateType.network);
46 + }
47 + );
48 + }
49 +
50 +}
1 +import 'package:flutter/material.dart';
2 +import 'package:one_poem/widgets/state_layout.dart';
3 +
4 +class BaseListProvider<T> extends ChangeNotifier {
5 +
6 + final List<T> _list = <T>[];
7 + List<T> get list => _list;
8 +
9 + bool hasMore = true;
10 +
11 + StateType stateType = StateType.loading;
12 +
13 + void setStateType(StateType stateType) {
14 + this.stateType = stateType;
15 + notifyListeners();
16 + }
17 +
18 + void add(T data) {
19 + _list.add(data);
20 + notifyListeners();
21 + }
22 +
23 + void addAll(List<T> data) {
24 + _list.addAll(data);
25 + notifyListeners();
26 + }
27 +
28 + void insert(int i, T data) {
29 + _list.insert(i, data);
30 + notifyListeners();
31 + }
32 +
33 + void insertAll(int i, List<T> data) {
34 + _list.insertAll(i, data);
35 + notifyListeners();
36 + }
37 +
38 + void remove(T data) {
39 + _list.remove(data);
40 + notifyListeners();
41 + }
42 +
43 + void removeAt(int i) {
44 + _list.removeAt(i);
45 + notifyListeners();
46 + }
47 +
48 + void clear() {
49 + _list.clear();
50 + notifyListeners();
51 + }
52 +
53 + void refresh() {
54 + notifyListeners();
55 + }
56 +}
...@@ -3,19 +3,18 @@ import 'package:flutter/scheduler.dart'; ...@@ -3,19 +3,18 @@ import 'package:flutter/scheduler.dart';
3 import 'package:flutter/services.dart'; 3 import 'package:flutter/services.dart';
4 import 'package:one_poem/res/resources.dart'; 4 import 'package:one_poem/res/resources.dart';
5 import 'package:one_poem/util/theme_utils.dart'; 5 import 'package:one_poem/util/theme_utils.dart';
6 - 6 +import 'package:one_poem/extension/int_extension.dart';
7 import 'load_image.dart'; 7 import 'load_image.dart';
8 import 'my_button.dart'; 8 import 'my_button.dart';
9 9
10 /// 搜索页的AppBar 10 /// 搜索页的AppBar
11 class SearchBar extends StatefulWidget implements PreferredSizeWidget { 11 class SearchBar extends StatefulWidget implements PreferredSizeWidget {
12 -
13 const SearchBar({ 12 const SearchBar({
14 Key? key, 13 Key? key,
15 this.hintText = '', 14 this.hintText = '',
16 this.backImg = 'assets/images/ic_back_black.png', 15 this.backImg = 'assets/images/ic_back_black.png',
17 this.onPressed, 16 this.onPressed,
18 - }): super(key: key); 17 + }) : super(key: key);
19 18
20 final String backImg; 19 final String backImg;
21 final String hintText; 20 final String hintText;
...@@ -25,11 +24,10 @@ class SearchBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -25,11 +24,10 @@ class SearchBar extends StatefulWidget implements PreferredSizeWidget {
25 _SearchBarState createState() => _SearchBarState(); 24 _SearchBarState createState() => _SearchBarState();
26 25
27 @override 26 @override
28 - Size get preferredSize => const Size.fromHeight(48.0); 27 + Size get preferredSize => Size.fromHeight(48.px);
29 } 28 }
30 29
31 class _SearchBarState extends State<SearchBar> { 30 class _SearchBarState extends State<SearchBar> {
32 -
33 final TextEditingController _controller = TextEditingController(); 31 final TextEditingController _controller = TextEditingController();
34 final FocusNode _focus = FocusNode(); 32 final FocusNode _focus = FocusNode();
35 33
...@@ -40,34 +38,26 @@ class _SearchBarState extends State<SearchBar> { ...@@ -40,34 +38,26 @@ class _SearchBarState extends State<SearchBar> {
40 super.dispose(); 38 super.dispose();
41 } 39 }
42 40
43 - // @override
44 - // void initState() {
45 - // WidgetsBinding.instance!.addPostFrameCallback((_) async {
46 - // SystemChannels.textInput.invokeMethod<void>('TextInput.updateConfig', const TextInputConfiguration().toJson());
47 - // SystemChannels.textInput.invokeMethod<void>('TextInput.hide');
48 - // });
49 - // super.initState();
50 - // }
51 -
52 @override 41 @override
53 Widget build(BuildContext context) { 42 Widget build(BuildContext context) {
54 final bool isDark = context.isDark; 43 final bool isDark = context.isDark;
55 - final Color iconColor = isDark ? Colours.dark_text_gray : Colours.text_gray_c; 44 + final Color iconColor =
45 + isDark ? Colours.dark_text_gray : Colours.text_gray_c;
56 46
57 final Widget back = Semantics( 47 final Widget back = Semantics(
58 label: '返回', 48 label: '返回',
59 child: SizedBox( 49 child: SizedBox(
60 - width: 48.0, 50 + width: 48.px,
61 - height: 48.0, 51 + height: 48.px,
62 child: InkWell( 52 child: InkWell(
63 onTap: () { 53 onTap: () {
64 _focus.unfocus(); 54 _focus.unfocus();
65 Navigator.maybePop(context); 55 Navigator.maybePop(context);
66 }, 56 },
67 - borderRadius: BorderRadius.circular(24.0), 57 + borderRadius: BorderRadius.circular(24.px),
68 child: Padding( 58 child: Padding(
69 key: const Key('search_back'), 59 key: const Key('search_back'),
70 - padding: const EdgeInsets.all(12.0), 60 + padding: EdgeInsets.all(12.px),
71 child: Image.asset( 61 child: Image.asset(
72 widget.backImg, 62 widget.backImg,
73 color: isDark ? Colours.dark_text : Colours.text, 63 color: isDark ? Colours.dark_text : Colours.text,
...@@ -77,43 +67,15 @@ class _SearchBarState extends State<SearchBar> { ...@@ -77,43 +67,15 @@ class _SearchBarState extends State<SearchBar> {
77 ), 67 ),
78 ); 68 );
79 69
80 - /// 使用2.0.0新增CupertinoSearchTextField 实现, 需添加依赖 cupertino_icons: ^1.0.2
81 - // final Widget textField1 = Expanded(child: Container(
82 - // height: 32.0,
83 - // child: CupertinoSearchTextField(
84 - // key: const Key('search_text_field'),
85 - // controller: _controller,
86 - // focusNode: _focus,
87 - // placeholder: widget.hintText,
88 - // placeholderStyle: Theme.of(context).inputDecorationTheme.hintStyle,
89 - // padding: const EdgeInsetsDirectional.fromSTEB(3.8, 0, 5, 0),
90 - // prefixInsets: const EdgeInsetsDirectional.fromSTEB(8, 0, 0, 0),
91 - // suffixInsets: const EdgeInsetsDirectional.fromSTEB(0, 0, 8, 0),
92 - // style: Theme.of(context).textTheme.subtitle1,
93 - // itemSize: 16.0,
94 - // itemColor: iconColor,
95 - // decoration: BoxDecoration(
96 - // color: isDark ? Colours.dark_material_bg : Colours.bg_gray,
97 - // borderRadius: BorderRadius.circular(4.0),
98 - // ),
99 - // onSubmitted: (String val) {
100 - // _focus.unfocus();
101 - // // 点击软键盘的动作按钮时的回调
102 - // widget.onPressed(val);
103 - // },
104 - // )
105 - // ));
106 -
107 final Widget textField = Expanded( 70 final Widget textField = Expanded(
108 child: Container( 71 child: Container(
109 - height: 32.0, 72 + height: 32.px,
110 decoration: BoxDecoration( 73 decoration: BoxDecoration(
111 color: isDark ? Colours.dark_material_bg : Colours.bg_gray, 74 color: isDark ? Colours.dark_material_bg : Colours.bg_gray,
112 - borderRadius: BorderRadius.circular(4.0), 75 + borderRadius: BorderRadius.circular(4.px),
113 ), 76 ),
114 child: TextField( 77 child: TextField(
115 key: const Key('search_text_field'), 78 key: const Key('search_text_field'),
116 -// autofocus: true,
117 controller: _controller, 79 controller: _controller,
118 focusNode: _focus, 80 focusNode: _focus,
119 textInputAction: TextInputAction.search, 81 textInputAction: TextInputAction.search,
...@@ -123,19 +85,24 @@ class _SearchBarState extends State<SearchBar> { ...@@ -123,19 +85,24 @@ class _SearchBarState extends State<SearchBar> {
123 widget.onPressed?.call(val); 85 widget.onPressed?.call(val);
124 }, 86 },
125 decoration: InputDecoration( 87 decoration: InputDecoration(
126 - contentPadding: const EdgeInsets.only(left: -8.0, right: -16.0, bottom: 14.0), 88 + contentPadding:
89 + EdgeInsets.only(left: -8.px, right: -16.px, bottom: 14.px),
127 border: InputBorder.none, 90 border: InputBorder.none,
128 icon: Padding( 91 icon: Padding(
129 - padding: const EdgeInsets.only(top: 8.0, bottom: 8.0, left: 8.0), 92 + padding: EdgeInsets.only(top: 8.px, bottom: 8.px, left: 8.px),
130 - child: LoadAssetImage('poem/order_search', color: iconColor,), 93 + child: LoadAssetImage(
94 + 'poem/poem_search',
95 + color: iconColor,
96 + ),
131 ), 97 ),
132 hintText: widget.hintText, 98 hintText: widget.hintText,
133 suffixIcon: GestureDetector( 99 suffixIcon: GestureDetector(
134 child: Semantics( 100 child: Semantics(
135 label: '清空', 101 label: '清空',
136 child: Padding( 102 child: Padding(
137 - padding: const EdgeInsets.only(left: 16.0, top: 8.0, bottom: 8.0), 103 + padding:
138 - child: LoadAssetImage('poem/order_delete', color: iconColor), 104 + EdgeInsets.only(left: 16.px, top: 8.px, bottom: 8.px),
105 + child: LoadAssetImage('poem/poem_delete', color: iconColor),
139 ), 106 ),
140 ), 107 ),
141 onTap: () { 108 onTap: () {
...@@ -151,13 +118,13 @@ class _SearchBarState extends State<SearchBar> { ...@@ -151,13 +118,13 @@ class _SearchBarState extends State<SearchBar> {
151 ); 118 );
152 119
153 final Widget search = MyButton( 120 final Widget search = MyButton(
154 - minHeight: 32.0, 121 + minHeight: 32.px,
155 - minWidth: 44.0, 122 + minWidth: 44.px,
156 fontSize: Dimens.font_sp14, 123 fontSize: Dimens.font_sp14,
157 - radius: 4.0, 124 + radius: 4.px,
158 - padding: const EdgeInsets.symmetric(horizontal: 8.0), 125 + padding: EdgeInsets.symmetric(horizontal: 8.px),
159 text: '搜索', 126 text: '搜索',
160 - onPressed:() { 127 + onPressed: () {
161 _focus.unfocus(); 128 _focus.unfocus();
162 widget.onPressed?.call(_controller.text); 129 widget.onPressed?.call(_controller.text);
163 }, 130 },
......