search users

This commit is contained in:
wgh19
2024-05-13 17:53:59 +08:00
parent 4b0ffa8b68
commit 0f225be531
5 changed files with 253 additions and 16 deletions

View File

@@ -309,3 +309,36 @@ class SearchOptions {
DateTime? endTime;
AgeLimit ageLimit = AgeLimit.unlimited;
}
/*
json:
{
"id": 20542044,
"name": "vocaloidhm01",
"account": "vocaloidhm01",
"profile_image_urls": {
"medium": "https://i.pximg.net/user-profile/img/2023/04/28/00/21/54/24348957_c74a61e78ddccb467417be7c37b5d463_170.jpg"
},
"is_followed": false,
"is_access_blocking_user": false
}
*/
class UserPreview {
final int id;
final String name;
final String account;
final String avatar;
bool isFollowed;
final bool isBlocking;
UserPreview(this.id, this.name, this.account, this.avatar, this.isFollowed,
this.isBlocking);
UserPreview.fromJson(Map<String, dynamic> json)
: id = json['id'],
name = json['name'],
account = json['account'],
avatar = json['profile_image_urls']['medium'],
isFollowed = json['is_followed'],
isBlocking = json['is_access_blocking_user'];
}

View File

@@ -302,12 +302,12 @@ class Network {
}
}
Future<Res<List<User>>> searchUsers(String keyword, [String? nextUrl]) async{
Future<Res<List<UserPreview>>> searchUsers(String keyword, [String? nextUrl]) async{
var path = nextUrl ?? "/v1/search/user?filter=for_android&word=${Uri.encodeComponent(keyword)}";
var res = await apiGet(path);
if (res.success) {
return Res(
(res.data["user_previews"] as List).map((e) => User.fromJson(e)).toList(),
(res.data["user_previews"] as List).map((e) => UserPreview.fromJson(e["user"])).toList(),
subData: res.data["next_url"]);
} else {
return Res.error(res.errorMessage);