diff --git a/lib/pages/html/controller.dart b/lib/pages/html/controller.dart index 7ce95a6f..499e88a8 100644 --- a/lib/pages/html/controller.dart +++ b/lib/pages/html/controller.dart @@ -45,11 +45,15 @@ class HtmlRenderController extends GetxController { } response = res; oid.value = res['commentId']; + queryReplyList(reqType: 'init'); return res; } // 请求评论 Future queryReplyList({reqType = 'init'}) async { + if (reqType == 'init') { + currentPage = 0; + } var res = await ReplyHttp.replyList( oid: oid.value, pageNum: currentPage + 1, diff --git a/lib/pages/html/view.dart b/lib/pages/html/view.dart index 06aec234..11a96076 100644 --- a/lib/pages/html/view.dart +++ b/lib/pages/html/view.dart @@ -32,7 +32,7 @@ class _HtmlRenderPageState extends State late String dynamicType; late int type; bool _isFabVisible = true; - late Future _futureBuilderFuture; + late final Future _futureBuilderFuture; late ScrollController scrollController; late AnimationController fabAnimationCtr; @@ -182,89 +182,73 @@ class _HtmlRenderPageState extends State children: [ SingleChildScrollView( controller: scrollController, - child: Column( - children: [ - FutureBuilder( - future: _futureBuilderFuture, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - var data = snapshot.data; - fabAnimationCtr.forward(); - if (data['status']) { - return Column( - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(12, 12, 12, 8), - child: Row( + child: FutureBuilder( + future: _futureBuilderFuture, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + var data = snapshot.data; + // fabAnimationCtr.forward(); + if (data != null && data['status']) { + return Column( + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(12, 12, 12, 8), + child: Row( + children: [ + NetworkImgLayer( + width: 40, + height: 40, + type: 'avatar', + src: _htmlRenderCtr.response['avatar']!, + ), + const SizedBox(width: 10), + Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - NetworkImgLayer( - width: 40, - height: 40, - type: 'avatar', - src: _htmlRenderCtr.response['avatar']!, + 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 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(), ], ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(12, 8, 12, 8), - child: HtmlRender( - htmlContent: _htmlRenderCtr.response['content'], + const Spacer(), + ], + ), + ), + 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( - 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( + ), + ), + Container( decoration: BoxDecoration( color: Theme.of(context).colorScheme.surface, border: Border( @@ -297,114 +281,78 @@ class _HtmlRenderPageState extends State ) ], ), - ) - : const SizedBox(), - ), - 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.isLoadingMore - ? ListView.builder( - itemCount: 5, - shrinkWrap: true, - physics: - const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - return const VideoReplySkeleton(); - }, - ) - : ListView.builder( - shrinkWrap: true, - physics: - const NeverScrollableScrollPhysics(), - itemCount: - _htmlRenderCtr.replyList.length + - 1, - itemBuilder: (context, index) { - if (index == - _htmlRenderCtr - .replyList.length) { - return Container( - padding: EdgeInsets.only( - 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); - }, - ); - } - }, + ), + Obx( + () => _htmlRenderCtr.replyList.isEmpty && + _htmlRenderCtr.isLoadingMore + ? ListView.builder( + itemCount: 5, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return const VideoReplySkeleton(); + }, + ) + : ListView.builder( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: + _htmlRenderCtr.replyList.length + 1, + itemBuilder: (context, index) { + if (index == + _htmlRenderCtr.replyList.length) { + return Container( + padding: EdgeInsets.only( + 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 CustomScrollView( - slivers: [ - HttpError( - errMsg: data['msg'], - fn: () => setState(() {}), - ) - ], - ); - } - } else { - // 骨架屏 - return ListView.builder( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemCount: 5, - itemBuilder: (context, index) { - return const VideoReplySkeleton(); - }, - ); - } - }, - ) - : const SizedBox(), - ) - ], + ); + } 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 { + return const Text('error'); + } + } else { + // 骨架屏 + return const SizedBox(); + } + }, ), ), Positioned(