Skip to content

Commit

Permalink
fix: 评论区表情suggest解析错误,评论区非空错误
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 23, 2024
1 parent b44dbdf commit 0a32b30
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 68 deletions.
95 changes: 65 additions & 30 deletions lib/models/user/my_emote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MyEmote {

MyEmote.fromJson(Map<String, dynamic> json) {
setting =
json['setting'] != null ? Setting.fromJson(json['setting']) : null;
json['setting'] != null ? Setting.fromJson(json['setting']) : null;
if (json['packages'] != null) {
packages = <Packages>[];
json['packages'].forEach((v) {
Expand Down Expand Up @@ -62,23 +62,23 @@ class Packages {
PackagesMeta? meta;
List<Emote>? emote;
PackagesFlags? flags;
dynamic label;
Label? label;
String? packageSubTitle;
int? refMid;

Packages(
{this.id,
this.text,
this.url,
this.mtime,
this.type,
this.attr,
this.meta,
this.emote,
this.flags,
this.label,
this.packageSubTitle,
this.refMid});
this.text,
this.url,
this.mtime,
this.type,
this.attr,
this.meta,
this.emote,
this.flags,
this.label,
this.packageSubTitle,
this.refMid});

Packages.fromJson(Map<String, dynamic> json) {
id = json['id'];
Expand All @@ -94,8 +94,9 @@ class Packages {
emote!.add(Emote.fromJson(v));
});
}
flags = json['flags'] != null ? PackagesFlags.fromJson(json['flags']) : null;
label = json['label'];
flags =
json['flags'] != null ? PackagesFlags.fromJson(json['flags']) : null;
label = json['label'] != null ? Label.fromJson(json['label']) : null;
packageSubTitle = json['package_sub_title'];
refMid = json['ref_mid'];
}
Expand All @@ -117,28 +118,58 @@ class Packages {
if (flags != null) {
data['flags'] = flags!.toJson();
}
data['label'] = label;
if (label != null) {
data['label'] = label!.toJson();
}
data['package_sub_title'] = packageSubTitle;
data['ref_mid'] = refMid;
return data;
}
}

class Label {
String? fontColor;
String? backgroundColor;
String? text;

Label({this.fontColor, this.backgroundColor, this.text});

Label.fromJson(Map<String, dynamic> json) {
fontColor = json['font_color'];
backgroundColor = json['background_color'];
text = json['text'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['font_color'] = fontColor;
data['background_color'] = backgroundColor;
data['text'] = text;
return data;
}
}

class PackagesMeta {
int? size;
int? itemId;
String? itemUrl;
int? assetId;

PackagesMeta({this.size, this.itemId});
PackagesMeta({this.size, this.itemId, this.itemUrl, this.assetId});

PackagesMeta.fromJson(Map<String, dynamic> json) {
size = json['size'];
itemId = json['item_id'];
itemUrl = json['item_url'];
assetId = json['asset_id'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['size'] = size;
data['item_id'] = itemId;
data['item_url'] = itemUrl;
data['asset_id'] = assetId;
return data;
}
}
Expand All @@ -158,16 +189,16 @@ class Emote {

Emote(
{this.id,
this.packageId,
this.text,
this.url,
this.mtime,
this.type,
this.attr,
this.meta,
this.flags,
this.activity,
this.gifUrl});
this.packageId,
this.text,
this.url,
this.mtime,
this.type,
this.attr,
this.meta,
this.flags,
this.activity,
this.gifUrl});

Emote.fromJson(Map<String, dynamic> json) {
id = json['id'];
Expand Down Expand Up @@ -214,7 +245,9 @@ class EmoteMeta {

EmoteMeta.fromJson(Map<String, dynamic> json) {
size = json['size'];
suggest = json['suggest'].cast<String>();
suggest = json['suggest'] == null
? null
: List<String>.from(json['suggest'].map((x) => x));
alias = json['alias'];
gifUrl = json['gif_url'];
}
Expand All @@ -231,16 +264,18 @@ class EmoteMeta {

class EmoteFlags {
bool? unlocked;
bool? recentUseForbid;

EmoteFlags({this.unlocked});

EmoteFlags({this.unlocked, this.recentUseForbid});
EmoteFlags.fromJson(Map<String, dynamic> json) {
unlocked = json['unlocked'];
recentUseForbid = json['recent_use_forbid'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['unlocked'] = unlocked;
data['recent_use_forbid'] = recentUseForbid;
return data;
}
}
Expand Down
84 changes: 46 additions & 38 deletions lib/pages/video/detail/reply/reply_emote/view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'package:PiliPalaX/models/user/my_emote.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
Expand Down Expand Up @@ -42,13 +43,15 @@ class _EmoteTabState extends State<EmoteTab> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: futureBuild,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
myEmote.packages != null) {
return Column(
children: [
Expanded(child: TabBarView(controller: _myEmoteTabController, children: [
future: futureBuild,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
myEmote != null &&
myEmote.packages != null) {
return Column(
children: [
Expanded(
child: TabBarView(controller: _myEmoteTabController, children: [
for (Packages i in myEmote.packages!) ...<Widget>[
GridView.builder(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
Expand All @@ -64,41 +67,46 @@ class _EmoteTabState extends State<EmoteTab> with TickerProviderStateMixin {
widget.onEmoteTap(i.emote![index].text!);
},
child: i.type == 4
? Text(i.emote![index].text!,overflow: TextOverflow.clip,maxLines: 1,)
? Text(
i.emote![index].text!,
overflow: TextOverflow.clip,
maxLines: 1,
)
: NetworkImgLayer(
width: 36,
height: 36,
type: 'emote',
src: i.emote![index].url,
),
width: 36,
height: 36,
type: 'emote',
src: i.emote![index].url?.split("@")[0]
),
);
},
),
],
]),),
SizedBox(
height: 45,
child: TabBar(
isScrollable: true,
controller: _myEmoteTabController,
tabs: [
for (var i in myEmote.packages!)
NetworkImgLayer(
width: 36,
height: 36,
type: 'emote',
src: i.url,
),
],
))
],
);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
},
);
]),
),
SizedBox(
height: 45,
child: TabBar(
isScrollable: true,
controller: _myEmoteTabController,
tabs: [
for (var i in myEmote.packages!)
NetworkImgLayer(
width: 36,
height: 36,
type: 'emote',
src: i.url,
),
],
))
],
);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
},
);
}
}
1 change: 1 addition & 0 deletions lib/pages/video/detail/reply/widgets/reply_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class ReplyItem extends StatelessWidget {
}

Widget content(BuildContext context) {
if (replyItem?.member == null) return const SizedBox();
final String heroTag = Utils.makeHeroTag(replyItem!.mid);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down

0 comments on commit 0a32b30

Please sign in to comment.