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,15 +182,14 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
children: [ children: [
SingleChildScrollView( SingleChildScrollView(
controller: scrollController, controller: scrollController,
child: Column( child: FutureBuilder(
children: [
FutureBuilder(
future: _futureBuilderFuture, future: _futureBuilderFuture,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) {
var data = snapshot.data; var data = snapshot.data;
fabAnimationCtr.forward(); // fabAnimationCtr.forward();
if (data['status']) { if (data != null && data['status']) {
return Column( return Column(
children: [ children: [
Padding( Padding(
@@ -205,8 +204,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
), ),
const SizedBox(width: 10), const SizedBox(width: 10),
Column( Column(
crossAxisAlignment: crossAxisAlignment: CrossAxisAlignment.start,
CrossAxisAlignment.start,
children: [ children: [
Text(_htmlRenderCtr.response['uname'], Text(_htmlRenderCtr.response['uname'],
style: TextStyle( style: TextStyle(
@@ -218,9 +216,8 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
Text( Text(
_htmlRenderCtr.response['updateTime'], _htmlRenderCtr.response['updateTime'],
style: TextStyle( style: TextStyle(
color: Theme.of(context) color:
.colorScheme Theme.of(context).colorScheme.outline,
.outline,
fontSize: Theme.of(context) fontSize: Theme.of(context)
.textTheme .textTheme
.labelSmall! .labelSmall!
@@ -251,20 +248,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
), ),
), ),
), ),
], Container(
);
} 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,46 +281,29 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
) )
], ],
), ),
)
: const SizedBox(),
), ),
Obx( Obx(
() => _htmlRenderCtr.oid.value != -1
? FutureBuilder(
future: _htmlRenderCtr.queryReplyList(),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.done) {
Map data = snapshot.data as Map;
if (snapshot.data['status']) {
// 请求成功
return Obx(
() => _htmlRenderCtr.replyList.isEmpty && () => _htmlRenderCtr.replyList.isEmpty &&
_htmlRenderCtr.isLoadingMore _htmlRenderCtr.isLoadingMore
? ListView.builder( ? ListView.builder(
itemCount: 5, itemCount: 5,
shrinkWrap: true, shrinkWrap: true,
physics: physics: const NeverScrollableScrollPhysics(),
const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) { itemBuilder: (context, index) {
return const VideoReplySkeleton(); return const VideoReplySkeleton();
}, },
) )
: ListView.builder( : ListView.builder(
shrinkWrap: true, shrinkWrap: true,
physics: physics: const NeverScrollableScrollPhysics(),
const NeverScrollableScrollPhysics(),
itemCount: itemCount:
_htmlRenderCtr.replyList.length + _htmlRenderCtr.replyList.length + 1,
1,
itemBuilder: (context, index) { itemBuilder: (context, index) {
if (index == if (index ==
_htmlRenderCtr _htmlRenderCtr.replyList.length) {
.replyList.length) {
return Container( return Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: bottom: MediaQuery.of(context)
MediaQuery.of(context)
.padding .padding
.bottom), .bottom),
height: MediaQuery.of(context) height: MediaQuery.of(context)
@@ -346,8 +313,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
child: Center( child: Center(
child: Obx( child: Obx(
() => Text( () => Text(
_htmlRenderCtr _htmlRenderCtr.noMore.value,
.noMore.value,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
color: Theme.of(context) color: Theme.of(context)
@@ -360,14 +326,13 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
); );
} else { } else {
return ReplyItem( return ReplyItem(
replyItem: _htmlRenderCtr replyItem:
.replyList[index], _htmlRenderCtr.replyList[index],
showReplyRow: true, showReplyRow: true,
replyLevel: '1', replyLevel: '1',
replyReply: (replyItem) => replyReply: (replyItem) =>
replyReply(replyItem), replyReply(replyItem),
replyType: replyType: ReplyType.values[type],
ReplyType.values[type],
addReply: (replyItem) { addReply: (replyItem) {
_htmlRenderCtr _htmlRenderCtr
.replyList[index].replies! .replyList[index].replies!
@@ -377,34 +342,17 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
} }
}, },
), ),
); ),
} else {
// 请求错误
return CustomScrollView(
slivers: [
HttpError(
errMsg: data['msg'],
fn: () => setState(() {}),
)
], ],
); );
} else {
return const Text('error');
} }
} else { } else {
// 骨架屏 // 骨架屏
return ListView.builder( return const SizedBox();
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: 5,
itemBuilder: (context, index) {
return const VideoReplySkeleton();
},
);
} }
}, },
)
: const SizedBox(),
)
],
), ),
), ),
Positioned( Positioned(