refactor dyn uplist

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-06-27 09:45:18 +08:00
parent 840f8d5a25
commit 5d15bf5e59
9 changed files with 228 additions and 275 deletions

View File

@@ -132,7 +132,7 @@ class Word {
style = json['style'] == null ? null : Style.fromJson(json['style']);
if (json['color'] case final String rawColor
when rawColor.startsWith('#')) {
color = ColourUtils.parse2Int(json['color']);
color = ColourUtils.parse2Int(rawColor);
}
fontLevel = json['font_level'];
}

View File

@@ -1,41 +1,43 @@
import 'package:PiliPlus/models_new/follow/list.dart';
import 'package:PiliPlus/utils/parse_int.dart';
class FollowUpModel {
FollowUpModel({
this.liveUsers,
required this.upList,
});
LiveUsers? liveUsers;
late List<UpItem> upList;
bool? hasMore;
String? offset;
FollowUpModel.fromJson(Map<String, dynamic> json) {
liveUsers = json['live_users'] != null
? LiveUsers.fromJson(json['live_users'])
: null;
upList =
(json['up_list']?['items'] as List?)
?.map<UpItem>((e) => UpItem.fromJson(e))
.toList() ??
<UpItem>[];
hasMore = json['up_list']?['has_more'];
offset = json['up_list']?['offset'];
}
}
class DynUpList {
List<UpItem>? upList;
bool? hasMore;
String? offset;
DynUpList.fromJson(Map<String, dynamic> json) {
upList = (json['items'] as List?)
?.map<UpItem>((e) => UpItem.fromJson(e))
void addAllUpList(List<UpItem> newList) {
if (upList != null) {
upList!.addAll(newList);
} else {
upList = newList;
}
}
factory FollowUpModel.fromJson(Map<String, dynamic> json) {
final model = FollowUpModel.fromUpList(json['up_list']);
final liveUsers = json['live_users'];
if (liveUsers != null) {
model.liveUsers = LiveUsers.fromJson(liveUsers);
}
return model;
}
FollowUpModel.fromUpList(Map<String, dynamic>? json) {
if (json != null) {
upList = (json['items'] as List?)
?.map((e) => UpItem.fromJson(e))
.toList();
hasMore = json['has_more'];
offset = json['offset'];
}
}
FollowUpModel.fromFollowList(Map<String, dynamic> json) {
upList = (json['list'] as List?)
?.map((e) => FollowItemModel.fromJson(e))
.toList();
hasMore = json['has_more'];
offset = json['offset'];
}
}