fix: 专栏评论区异常重载且丢失数据

This commit is contained in:
orz12
2024-02-26 13:43:54 +08:00
parent c1a66fd1d5
commit 34925ae92f
2 changed files with 137 additions and 185 deletions

View File

@@ -45,11 +45,15 @@ class HtmlRenderController extends GetxController {
} }
response = res; response = res;
oid.value = res['commentId']; oid.value = res['commentId'];
queryReplyList(reqType: 'init');
return res; return res;
} }
// 请求评论 // 请求评论
Future queryReplyList({reqType = 'init'}) async { Future queryReplyList({reqType = 'init'}) async {
if (reqType == 'init') {
currentPage = 0;
}
var res = await ReplyHttp.replyList( var res = await ReplyHttp.replyList(
oid: oid.value, oid: oid.value,
pageNum: currentPage + 1, pageNum: currentPage + 1,

View File

@@ -32,7 +32,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
late String dynamicType; late String dynamicType;
late int type; late int type;
bool _isFabVisible = true; bool _isFabVisible = true;
late Future _futureBuilderFuture; late final Future _futureBuilderFuture;
late ScrollController scrollController; late ScrollController scrollController;
late AnimationController fabAnimationCtr; late AnimationController fabAnimationCtr;
@@ -182,89 +182,73 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
children: [ children: [
SingleChildScrollView( SingleChildScrollView(
controller: scrollController, controller: scrollController,
child: Column( child: FutureBuilder(
children: [ future: _futureBuilderFuture,
FutureBuilder( builder: (context, snapshot) {
future: _futureBuilderFuture, if (snapshot.connectionState == ConnectionState.done &&
builder: (context, snapshot) { snapshot.hasData) {
if (snapshot.connectionState == ConnectionState.done) { var data = snapshot.data;
var data = snapshot.data; // fabAnimationCtr.forward();
fabAnimationCtr.forward(); if (data != null && data['status']) {
if (data['status']) { return Column(
return Column( children: [
children: [ Padding(
Padding( padding: const EdgeInsets.fromLTRB(12, 12, 12, 8),
padding: const EdgeInsets.fromLTRB(12, 12, 12, 8), child: Row(
child: Row( children: [
NetworkImgLayer(
width: 40,
height: 40,
type: 'avatar',
src: _htmlRenderCtr.response['avatar']!,
),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
NetworkImgLayer( Text(_htmlRenderCtr.response['uname'],
width: 40, style: TextStyle(
height: 40, fontSize: Theme.of(context)
type: 'avatar', .textTheme
src: _htmlRenderCtr.response['avatar']!, .titleSmall!
.fontSize,
)),
Text(
_htmlRenderCtr.response['updateTime'],
style: TextStyle(
color:
Theme.of(context).colorScheme.outline,
fontSize: Theme.of(context)
.textTheme
.labelSmall!
.fontSize,
),
), ),
const SizedBox(width: 10),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(_htmlRenderCtr.response['uname'],
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleSmall!
.fontSize,
)),
Text(
_htmlRenderCtr.response['updateTime'],
style: TextStyle(
color: Theme.of(context)
.colorScheme
.outline,
fontSize: Theme.of(context)
.textTheme
.labelSmall!
.fontSize,
),
),
],
),
const Spacer(),
], ],
), ),
), const Spacer(),
Padding( ],
padding: const EdgeInsets.fromLTRB(12, 8, 12, 8), ),
child: HtmlRender( ),
htmlContent: _htmlRenderCtr.response['content'], Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 8),
child: HtmlRender(
htmlContent: _htmlRenderCtr.response['content'],
),
),
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: 8,
color: Theme.of(context)
.dividerColor
.withOpacity(0.05),
), ),
), ),
Container( ),
decoration: BoxDecoration( ),
border: Border( Container(
bottom: BorderSide(
width: 8,
color: Theme.of(context)
.dividerColor
.withOpacity(0.05),
),
),
),
),
],
);
} else {
return const Text('error');
}
} else {
// 骨架屏
return const SizedBox();
}
},
),
Obx(
() => _htmlRenderCtr.oid.value != -1
? Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
border: Border( border: Border(
@@ -297,114 +281,78 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
) )
], ],
), ),
) ),
: const SizedBox(), Obx(
), () => _htmlRenderCtr.replyList.isEmpty &&
Obx( _htmlRenderCtr.isLoadingMore
() => _htmlRenderCtr.oid.value != -1 ? ListView.builder(
? FutureBuilder( itemCount: 5,
future: _htmlRenderCtr.queryReplyList(), shrinkWrap: true,
builder: (context, snapshot) { physics: const NeverScrollableScrollPhysics(),
if (snapshot.connectionState == itemBuilder: (context, index) {
ConnectionState.done) { return const VideoReplySkeleton();
Map data = snapshot.data as Map; },
if (snapshot.data['status']) { )
// 请求成功 : ListView.builder(
return Obx( shrinkWrap: true,
() => _htmlRenderCtr.replyList.isEmpty && physics: const NeverScrollableScrollPhysics(),
_htmlRenderCtr.isLoadingMore itemCount:
? ListView.builder( _htmlRenderCtr.replyList.length + 1,
itemCount: 5, itemBuilder: (context, index) {
shrinkWrap: true, if (index ==
physics: _htmlRenderCtr.replyList.length) {
const NeverScrollableScrollPhysics(), return Container(
itemBuilder: (context, index) { padding: EdgeInsets.only(
return const VideoReplySkeleton(); bottom: MediaQuery.of(context)
}, .padding
) .bottom),
: ListView.builder( height: MediaQuery.of(context)
shrinkWrap: true, .padding
physics: .bottom +
const NeverScrollableScrollPhysics(), 100,
itemCount: child: Center(
_htmlRenderCtr.replyList.length + child: Obx(
1, () => Text(
itemBuilder: (context, index) { _htmlRenderCtr.noMore.value,
if (index == style: TextStyle(
_htmlRenderCtr fontSize: 12,
.replyList.length) { color: Theme.of(context)
return Container( .colorScheme
padding: EdgeInsets.only( .outline,
bottom: ),
MediaQuery.of(context) ),
.padding ),
.bottom),
height: MediaQuery.of(context)
.padding
.bottom +
100,
child: Center(
child: Obx(
() => Text(
_htmlRenderCtr
.noMore.value,
style: TextStyle(
fontSize: 12,
color: Theme.of(context)
.colorScheme
.outline,
),
),
),
),
);
} else {
return ReplyItem(
replyItem: _htmlRenderCtr
.replyList[index],
showReplyRow: true,
replyLevel: '1',
replyReply: (replyItem) =>
replyReply(replyItem),
replyType:
ReplyType.values[type],
addReply: (replyItem) {
_htmlRenderCtr
.replyList[index].replies!
.add(replyItem);
},
);
}
},
), ),
); );
} else { } else {
// 请求错误 return ReplyItem(
return CustomScrollView( replyItem:
slivers: [ _htmlRenderCtr.replyList[index],
HttpError( showReplyRow: true,
errMsg: data['msg'], replyLevel: '1',
fn: () => setState(() {}), replyReply: (replyItem) =>
) replyReply(replyItem),
], replyType: ReplyType.values[type],
); addReply: (replyItem) {
} _htmlRenderCtr
} else { .replyList[index].replies!
// 骨架屏 .add(replyItem);
return ListView.builder( },
shrinkWrap: true, );
physics: const NeverScrollableScrollPhysics(), }
itemCount: 5, },
itemBuilder: (context, index) { ),
return const VideoReplySkeleton(); ),
}, ],
); );
} } else {
}, return const Text('error');
) }
: const SizedBox(), } else {
) // 骨架屏
], return const SizedBox();
}
},
), ),
), ),
Positioned( Positioned(