mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: html page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -6,19 +6,20 @@ import 'package:cached_network_image/cached_network_image.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_html/flutter_html.dart';
|
import 'package:flutter_html/flutter_html.dart';
|
||||||
import 'network_img_layer.dart';
|
import 'network_img_layer.dart';
|
||||||
|
import 'package:html/dom.dart' as dom;
|
||||||
|
|
||||||
Widget htmlRender({
|
Widget htmlRender({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
String? htmlContent,
|
required dom.Element element,
|
||||||
int? imgCount,
|
int? imgCount,
|
||||||
List<String>? imgList,
|
List<String>? imgList,
|
||||||
required double constrainedWidth,
|
required double maxWidth,
|
||||||
Function(List<String>, int)? callback,
|
Function(List<String>, int)? callback,
|
||||||
}) {
|
}) {
|
||||||
debugPrint('htmlRender');
|
debugPrint('htmlRender');
|
||||||
return SelectionArea(
|
return SelectionArea(
|
||||||
child: Html(
|
child: Html.fromElement(
|
||||||
data: htmlContent,
|
documentElement: element,
|
||||||
onLinkTap: (String? url, Map<String, String> buildContext, attributes) {},
|
onLinkTap: (String? url, Map<String, String> buildContext, attributes) {},
|
||||||
extensions: [
|
extensions: [
|
||||||
TagExtension(
|
TagExtension(
|
||||||
@@ -43,7 +44,7 @@ Widget htmlRender({
|
|||||||
?.group(1);
|
?.group(1);
|
||||||
if (clazz?.contains('cut-off') == true || height != null) {
|
if (clazz?.contains('cut-off') == true || height != null) {
|
||||||
return CachedNetworkImage(
|
return CachedNetworkImage(
|
||||||
width: constrainedWidth,
|
width: maxWidth,
|
||||||
height: height != null ? double.parse(height) : null,
|
height: height != null ? double.parse(height) : null,
|
||||||
imageUrl: Utils.thumbnailImgUrl(imgUrl),
|
imageUrl: Utils.thumbnailImgUrl(imgUrl),
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
@@ -62,7 +63,7 @@ Widget htmlRender({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: NetworkImgLayer(
|
child: NetworkImgLayer(
|
||||||
width: isEmote ? 22 : constrainedWidth,
|
width: isEmote ? 22 : maxWidth,
|
||||||
height: isEmote ? 22 : 200,
|
height: isEmote ? 22 : 200,
|
||||||
src: imgUrl,
|
src: imgUrl,
|
||||||
ignoreHeight: !isEmote,
|
ignoreHeight: !isEmote,
|
||||||
@@ -70,7 +71,7 @@ Widget htmlRender({
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return const SizedBox();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -500,10 +500,4 @@ https://api.bilibili.com/x/v2/reply/reply?oid=$oid&pn=1&ps=20&root=${rpid ?? rep
|
|||||||
SmartDialog.showToast(res['msg']);
|
SmartDialog.showToast(res['msg']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future onReload() {
|
|
||||||
scrollController.jumpToTop();
|
|
||||||
return super.onReload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
|||||||
import 'package:PiliPlus/models/common/reply_type.dart';
|
import 'package:PiliPlus/models/common/reply_type.dart';
|
||||||
import 'package:PiliPlus/pages/video/detail/reply_reply/index.dart';
|
import 'package:PiliPlus/pages/video/detail/reply_reply/index.dart';
|
||||||
import 'package:PiliPlus/utils/feed_back.dart';
|
import 'package:PiliPlus/utils/feed_back.dart';
|
||||||
|
import 'package:html/parser.dart' as parser;
|
||||||
|
|
||||||
import '../../utils/grid.dart';
|
import '../../utils/grid.dart';
|
||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
@@ -229,7 +230,303 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
appBar: AppBar(
|
appBar: _buildAppBar,
|
||||||
|
body: Stack(
|
||||||
|
children: [
|
||||||
|
SafeArea(
|
||||||
|
top: false,
|
||||||
|
bottom: false,
|
||||||
|
child: Builder(
|
||||||
|
builder: (context) {
|
||||||
|
final isPortrait = context.orientation == Orientation.portrait;
|
||||||
|
double padding =
|
||||||
|
max(context.width / 2 - Grid.smallCardWidth, 0);
|
||||||
|
if (isPortrait) {
|
||||||
|
return LayoutBuilder(builder: (context, constraints) {
|
||||||
|
final maxWidth = constraints.maxWidth - 2 * padding - 24;
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: padding),
|
||||||
|
child: CustomScrollView(
|
||||||
|
controller: _htmlRenderCtr.scrollController,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
slivers: [
|
||||||
|
_buildHeader,
|
||||||
|
_buildContent(maxWidth),
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: Divider(
|
||||||
|
thickness: 8,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.dividerColor
|
||||||
|
.withOpacity(0.05),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_buildReplyHeader,
|
||||||
|
Obx(() => _buildReplyList(
|
||||||
|
_htmlRenderCtr.loadingState.value)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: _ratio[0].toInt(),
|
||||||
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final maxWidth =
|
||||||
|
constraints.maxWidth - padding / 4 - 24;
|
||||||
|
return CustomScrollView(
|
||||||
|
controller: _htmlRenderCtr.scrollController,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
slivers: [
|
||||||
|
SliverPadding(
|
||||||
|
padding: EdgeInsets.only(left: padding / 4),
|
||||||
|
sliver: _buildHeader,
|
||||||
|
),
|
||||||
|
SliverPadding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
left: padding / 4,
|
||||||
|
bottom:
|
||||||
|
MediaQuery.paddingOf(context).bottom +
|
||||||
|
80,
|
||||||
|
),
|
||||||
|
sliver: _buildContent(maxWidth),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
VerticalDivider(
|
||||||
|
thickness: 8,
|
||||||
|
color: Theme.of(context).dividerColor.withOpacity(0.05),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: _ratio[1].toInt(),
|
||||||
|
child: Scaffold(
|
||||||
|
key: _key,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
body: refreshIndicator(
|
||||||
|
onRefresh: () async {
|
||||||
|
await _htmlRenderCtr.onRefresh();
|
||||||
|
},
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(right: padding / 4),
|
||||||
|
child: CustomScrollView(
|
||||||
|
controller: _htmlRenderCtr.scrollController,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
slivers: [
|
||||||
|
_buildReplyHeader,
|
||||||
|
Obx(() => _buildReplyList(
|
||||||
|
_htmlRenderCtr.loadingState.value)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_buildBottom,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildContent(double maxWidth) => SliverPadding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
|
sliver: Obx(
|
||||||
|
() {
|
||||||
|
if (_htmlRenderCtr.loaded.value) {
|
||||||
|
if (_htmlRenderCtr.response['isJsonContent'] == true) {
|
||||||
|
return articleContent(
|
||||||
|
context: context,
|
||||||
|
list: _htmlRenderCtr.response['content'],
|
||||||
|
callback: _getImageCallback,
|
||||||
|
maxWidth: maxWidth,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// html
|
||||||
|
var res = parser.parse(_htmlRenderCtr.response['content']);
|
||||||
|
return SliverList.builder(
|
||||||
|
itemCount: res.body!.children.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return htmlRender(
|
||||||
|
context: context,
|
||||||
|
element: res.body!.children[index],
|
||||||
|
maxWidth: maxWidth,
|
||||||
|
callback: _getImageCallback,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return const SliverToBoxAdapter();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _buildReplyList(LoadingState<List<ReplyInfo>?> loadingState) {
|
||||||
|
return switch (loadingState) {
|
||||||
|
Loading() => SliverList.builder(
|
||||||
|
itemCount: 5,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return const VideoReplySkeleton();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Success() => loadingState.response?.isNotEmpty == true
|
||||||
|
? SliverList.builder(
|
||||||
|
itemCount: loadingState.response!.length + 1,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index == loadingState.response!.length) {
|
||||||
|
_htmlRenderCtr.onLoadMore();
|
||||||
|
return Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
bottom: MediaQuery.of(context).padding.bottom),
|
||||||
|
height: 125,
|
||||||
|
child: Text(
|
||||||
|
_htmlRenderCtr.isEnd.not
|
||||||
|
? '加载中...'
|
||||||
|
: loadingState.response!.isEmpty
|
||||||
|
? '还没有评论'
|
||||||
|
: '没有更多了',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Theme.of(context).colorScheme.outline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return ReplyItemGrpc(
|
||||||
|
replyItem: loadingState.response![index],
|
||||||
|
replyLevel: '1',
|
||||||
|
replyReply: (replyItem, id) =>
|
||||||
|
replyReply(context, replyItem, id),
|
||||||
|
onReply: () {
|
||||||
|
_htmlRenderCtr.onReply(
|
||||||
|
context,
|
||||||
|
replyItem: loadingState.response![index],
|
||||||
|
index: index,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onDelete: (subIndex) =>
|
||||||
|
_htmlRenderCtr.onRemove(index, subIndex),
|
||||||
|
upMid: _htmlRenderCtr.upMid,
|
||||||
|
callback: _getImageCallback,
|
||||||
|
onCheckReply: (item) =>
|
||||||
|
_htmlRenderCtr.onCheckReply(context, item),
|
||||||
|
onToggleTop: (isUpTop, rpid) => _htmlRenderCtr.onToggleTop(
|
||||||
|
index,
|
||||||
|
_htmlRenderCtr.oid,
|
||||||
|
_htmlRenderCtr.type,
|
||||||
|
isUpTop,
|
||||||
|
rpid,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: HttpError(
|
||||||
|
onReload: _htmlRenderCtr.onReload,
|
||||||
|
),
|
||||||
|
Error() => HttpError(
|
||||||
|
errMsg: loadingState.errMsg,
|
||||||
|
onReload: _htmlRenderCtr.onReload,
|
||||||
|
),
|
||||||
|
LoadingState() => throw UnimplementedError(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget get _buildReplyHeader {
|
||||||
|
return SliverToBoxAdapter(
|
||||||
|
child: Container(
|
||||||
|
height: 45,
|
||||||
|
padding: const EdgeInsets.only(left: 12, right: 6),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Text('回复'),
|
||||||
|
const Spacer(),
|
||||||
|
SizedBox(
|
||||||
|
height: 35,
|
||||||
|
child: TextButton.icon(
|
||||||
|
onPressed: () => _htmlRenderCtr.queryBySort(),
|
||||||
|
icon: const Icon(Icons.sort, size: 16),
|
||||||
|
label: Obx(
|
||||||
|
() => Text(
|
||||||
|
_htmlRenderCtr.sortType.value.label,
|
||||||
|
style: const TextStyle(fontSize: 13),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget get _buildHeader => SliverToBoxAdapter(
|
||||||
|
child: Obx(
|
||||||
|
() => _htmlRenderCtr.loaded.value
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(12, 12, 12, 8),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
if (_htmlRenderCtr.mid != null) {
|
||||||
|
Get.toNamed('/member?mid=${_htmlRenderCtr.mid}');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
NetworkImgLayer(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
type: 'avatar',
|
||||||
|
src: _htmlRenderCtr.response['avatar']!,
|
||||||
|
),
|
||||||
|
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 SizedBox.shrink(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
PreferredSizeWidget get _buildAppBar => AppBar(
|
||||||
title: Text(title),
|
title: Text(title),
|
||||||
actions: [
|
actions: [
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
@@ -340,123 +637,12 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 6)
|
const SizedBox(width: 6)
|
||||||
],
|
],
|
||||||
),
|
|
||||||
body: SafeArea(
|
|
||||||
top: false,
|
|
||||||
bottom: false,
|
|
||||||
child: Stack(
|
|
||||||
children: [
|
|
||||||
OrientationBuilder(
|
|
||||||
builder: (context, orientation) {
|
|
||||||
double padding =
|
|
||||||
max(context.width / 2 - Grid.smallCardWidth, 0);
|
|
||||||
return Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
flex: _ratio[0].toInt(),
|
|
||||||
child: CustomScrollView(
|
|
||||||
controller: _htmlRenderCtr.scrollController,
|
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
slivers: [
|
|
||||||
SliverPadding(
|
|
||||||
padding: orientation == Orientation.portrait
|
|
||||||
? EdgeInsets.symmetric(horizontal: padding)
|
|
||||||
: EdgeInsets.only(left: padding / 4),
|
|
||||||
sliver: SliverToBoxAdapter(
|
|
||||||
child: Obx(
|
|
||||||
() => _htmlRenderCtr.loaded.value
|
|
||||||
? _buildHeader
|
|
||||||
: const SizedBox(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SliverPadding(
|
|
||||||
padding: orientation == Orientation.portrait
|
|
||||||
? EdgeInsets.symmetric(horizontal: padding)
|
|
||||||
: EdgeInsets.only(
|
|
||||||
left: padding / 4,
|
|
||||||
bottom:
|
|
||||||
MediaQuery.paddingOf(context).bottom +
|
|
||||||
80,
|
|
||||||
),
|
|
||||||
sliver: _buildContent,
|
|
||||||
),
|
|
||||||
if (orientation == Orientation.portrait) ...[
|
|
||||||
SliverPadding(
|
|
||||||
padding:
|
|
||||||
EdgeInsets.symmetric(horizontal: padding),
|
|
||||||
sliver: SliverToBoxAdapter(
|
|
||||||
child: Divider(
|
|
||||||
thickness: 8,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.dividerColor
|
|
||||||
.withOpacity(0.05),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SliverPadding(
|
|
||||||
padding:
|
|
||||||
EdgeInsets.symmetric(horizontal: padding),
|
|
||||||
sliver: SliverToBoxAdapter(child: replyHeader()),
|
|
||||||
),
|
|
||||||
SliverPadding(
|
|
||||||
padding:
|
|
||||||
EdgeInsets.symmetric(horizontal: padding),
|
|
||||||
sliver: Obx(
|
|
||||||
() => replyList(
|
|
||||||
_htmlRenderCtr.loadingState.value),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (orientation == Orientation.landscape) ...[
|
|
||||||
VerticalDivider(
|
|
||||||
thickness: 8,
|
|
||||||
color: Theme.of(context).dividerColor.withOpacity(0.05),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
flex: _ratio[1].toInt(),
|
|
||||||
child: Scaffold(
|
|
||||||
key: _key,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
body: refreshIndicator(
|
|
||||||
onRefresh: () async {
|
|
||||||
await _htmlRenderCtr.onRefresh();
|
|
||||||
},
|
|
||||||
child: CustomScrollView(
|
|
||||||
controller: _htmlRenderCtr.scrollController,
|
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
slivers: [
|
|
||||||
SliverPadding(
|
|
||||||
padding: EdgeInsets.only(right: padding / 4),
|
|
||||||
sliver: SliverToBoxAdapter(
|
|
||||||
child: replyHeader(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SliverPadding(
|
|
||||||
padding: EdgeInsets.only(right: padding / 4),
|
|
||||||
sliver: Obx(
|
|
||||||
() => replyList(
|
|
||||||
_htmlRenderCtr.loadingState.value),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
},
|
|
||||||
),
|
Widget get _buildBottom => Positioned(
|
||||||
Positioned(
|
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
|
right: 0,
|
||||||
child: SlideTransition(
|
child: SlideTransition(
|
||||||
position: Tween<Offset>(
|
position: Tween<Offset>(
|
||||||
begin: const Offset(0, 1),
|
begin: const Offset(0, 1),
|
||||||
@@ -486,8 +672,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
right: 14,
|
right: 14,
|
||||||
bottom:
|
bottom: MediaQuery.of(context).padding.bottom + 14,
|
||||||
MediaQuery.of(context).padding.bottom + 14,
|
|
||||||
),
|
),
|
||||||
child: button(),
|
child: button(),
|
||||||
),
|
),
|
||||||
@@ -503,18 +688,15 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
bottom: 14 +
|
bottom: 14 +
|
||||||
(_htmlRenderCtr.item.value.idStr != null
|
(_htmlRenderCtr.item.value.idStr != null
|
||||||
? 0
|
? 0
|
||||||
: MediaQuery.of(context)
|
: MediaQuery.of(context).padding.bottom),
|
||||||
.padding
|
|
||||||
.bottom),
|
|
||||||
),
|
),
|
||||||
child: button(),
|
child: button(),
|
||||||
),
|
),
|
||||||
_htmlRenderCtr.item.value.idStr != null
|
_htmlRenderCtr.item.value.idStr != null
|
||||||
? Container(
|
? Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context)
|
color:
|
||||||
.colorScheme
|
Theme.of(context).colorScheme.surface,
|
||||||
.surface,
|
|
||||||
border: Border(
|
border: Border(
|
||||||
top: BorderSide(
|
top: BorderSide(
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
@@ -526,8 +708,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
),
|
),
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
bottom:
|
bottom:
|
||||||
MediaQuery.paddingOf(context)
|
MediaQuery.paddingOf(context).bottom),
|
||||||
.bottom),
|
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment:
|
||||||
MainAxisAlignment.spaceAround,
|
MainAxisAlignment.spaceAround,
|
||||||
@@ -543,8 +724,8 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
useSafeArea: true,
|
useSafeArea: true,
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
RepostPanel(
|
RepostPanel(
|
||||||
item: _htmlRenderCtr
|
item:
|
||||||
.item.value,
|
_htmlRenderCtr.item.value,
|
||||||
callback: () {
|
callback: () {
|
||||||
int count = int.tryParse(
|
int count = int.tryParse(
|
||||||
_htmlRenderCtr
|
_htmlRenderCtr
|
||||||
@@ -563,12 +744,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
?.moduleStat
|
?.moduleStat
|
||||||
?.forward!
|
?.forward!
|
||||||
.count =
|
.count =
|
||||||
(count + 1)
|
(count + 1).toString();
|
||||||
.toString();
|
if (btnContext.mounted) {
|
||||||
if (btnContext
|
(btnContext as Element?)
|
||||||
.mounted) {
|
|
||||||
(btnContext
|
|
||||||
as Element?)
|
|
||||||
?.markNeedsBuild();
|
?.markNeedsBuild();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -576,8 +754,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
FontAwesomeIcons
|
FontAwesomeIcons.shareFromSquare,
|
||||||
.shareFromSquare,
|
|
||||||
size: 16,
|
size: 16,
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
@@ -585,10 +762,10 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
semanticLabel: "转发",
|
semanticLabel: "转发",
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: const EdgeInsets
|
padding:
|
||||||
.fromLTRB(15, 0, 15, 0),
|
const EdgeInsets.fromLTRB(
|
||||||
foregroundColor:
|
15, 0, 15, 0),
|
||||||
Theme.of(context)
|
foregroundColor: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.outline,
|
.outline,
|
||||||
),
|
),
|
||||||
@@ -629,35 +806,29 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
semanticLabel: "分享",
|
semanticLabel: "分享",
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding:
|
padding: const EdgeInsets.fromLTRB(
|
||||||
const EdgeInsets.fromLTRB(
|
|
||||||
15, 0, 15, 0),
|
15, 0, 15, 0),
|
||||||
foregroundColor:
|
foregroundColor: Theme.of(context)
|
||||||
Theme.of(context)
|
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.outline,
|
.outline,
|
||||||
),
|
),
|
||||||
label: const Text('分享'),
|
label: const Text('分享'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (_htmlRenderCtr
|
if (_htmlRenderCtr.favStat['status'])
|
||||||
.favStat['status'])
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextButton.icon(
|
child: TextButton.icon(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_htmlRenderCtr.onFav();
|
_htmlRenderCtr.onFav();
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
_htmlRenderCtr.favStat[
|
_htmlRenderCtr.favStat['isFav'] ==
|
||||||
'isFav'] ==
|
|
||||||
true
|
true
|
||||||
? FontAwesomeIcons
|
? FontAwesomeIcons.solidStar
|
||||||
.solidStar
|
|
||||||
: FontAwesomeIcons.star,
|
: FontAwesomeIcons.star,
|
||||||
size: 16,
|
size: 16,
|
||||||
color:
|
color: _htmlRenderCtr
|
||||||
_htmlRenderCtr.favStat[
|
.favStat['isFav'] ==
|
||||||
'isFav'] ==
|
|
||||||
true
|
true
|
||||||
? Theme.of(context)
|
? Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
@@ -668,10 +839,10 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
semanticLabel: "收藏",
|
semanticLabel: "收藏",
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: const EdgeInsets
|
padding:
|
||||||
.fromLTRB(15, 0, 15, 0),
|
const EdgeInsets.fromLTRB(
|
||||||
foregroundColor:
|
15, 0, 15, 0),
|
||||||
Theme.of(context)
|
foregroundColor: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.outline,
|
.outline,
|
||||||
),
|
),
|
||||||
@@ -682,10 +853,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (context) =>
|
builder: (context) => TextButton.icon(
|
||||||
TextButton.icon(
|
onPressed: () =>
|
||||||
onPressed: () => RequestUtils
|
RequestUtils.onLikeDynamic(
|
||||||
.onLikeDynamic(
|
|
||||||
_htmlRenderCtr.item.value,
|
_htmlRenderCtr.item.value,
|
||||||
() {
|
() {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
@@ -705,8 +875,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
true
|
true
|
||||||
? FontAwesomeIcons
|
? FontAwesomeIcons
|
||||||
.solidThumbsUp
|
.solidThumbsUp
|
||||||
: FontAwesomeIcons
|
: FontAwesomeIcons.thumbsUp,
|
||||||
.thumbsUp,
|
|
||||||
size: 16,
|
size: 16,
|
||||||
color: _htmlRenderCtr
|
color: _htmlRenderCtr
|
||||||
.item
|
.item
|
||||||
@@ -722,8 +891,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
: Theme.of(context)
|
: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.outline,
|
.outline,
|
||||||
semanticLabel:
|
semanticLabel: _htmlRenderCtr
|
||||||
_htmlRenderCtr
|
|
||||||
.item
|
.item
|
||||||
.value
|
.value
|
||||||
.modules
|
.modules
|
||||||
@@ -735,20 +903,18 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
: "点赞",
|
: "点赞",
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: const EdgeInsets
|
padding:
|
||||||
.fromLTRB(15, 0, 15, 0),
|
const EdgeInsets.fromLTRB(
|
||||||
foregroundColor:
|
15, 0, 15, 0),
|
||||||
Theme.of(context)
|
foregroundColor: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.outline,
|
.outline,
|
||||||
),
|
),
|
||||||
label: AnimatedSwitcher(
|
label: AnimatedSwitcher(
|
||||||
duration: const Duration(
|
duration: const Duration(
|
||||||
milliseconds: 400),
|
milliseconds: 400),
|
||||||
transitionBuilder:
|
transitionBuilder: (Widget child,
|
||||||
(Widget child,
|
Animation<double> animation) {
|
||||||
Animation<double>
|
|
||||||
animation) {
|
|
||||||
return ScaleTransition(
|
return ScaleTransition(
|
||||||
scale: animation,
|
scale: animation,
|
||||||
child: child);
|
child: child);
|
||||||
@@ -802,178 +968,5 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget replyList(LoadingState<List<ReplyInfo>?> loadingState) {
|
|
||||||
return switch (loadingState) {
|
|
||||||
Loading() => SliverList.builder(
|
|
||||||
itemCount: 5,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return const VideoReplySkeleton();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Success() => loadingState.response?.isNotEmpty == true
|
|
||||||
? SliverList.builder(
|
|
||||||
itemCount: loadingState.response!.length + 1,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index == loadingState.response!.length) {
|
|
||||||
_htmlRenderCtr.onLoadMore();
|
|
||||||
return Container(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
margin: EdgeInsets.only(
|
|
||||||
bottom: MediaQuery.of(context).padding.bottom),
|
|
||||||
height: 125,
|
|
||||||
child: Text(
|
|
||||||
_htmlRenderCtr.isEnd.not
|
|
||||||
? '加载中...'
|
|
||||||
: loadingState.response!.isEmpty
|
|
||||||
? '还没有评论'
|
|
||||||
: '没有更多了',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Theme.of(context).colorScheme.outline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return ReplyItemGrpc(
|
|
||||||
replyItem: loadingState.response![index],
|
|
||||||
replyLevel: '1',
|
|
||||||
replyReply: (replyItem, id) =>
|
|
||||||
replyReply(context, replyItem, id),
|
|
||||||
onReply: () {
|
|
||||||
_htmlRenderCtr.onReply(
|
|
||||||
context,
|
|
||||||
replyItem: loadingState.response![index],
|
|
||||||
index: index,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onDelete: (subIndex) =>
|
|
||||||
_htmlRenderCtr.onRemove(index, subIndex),
|
|
||||||
upMid: _htmlRenderCtr.upMid,
|
|
||||||
callback: _getImageCallback,
|
|
||||||
onCheckReply: (item) =>
|
|
||||||
_htmlRenderCtr.onCheckReply(context, item),
|
|
||||||
onToggleTop: (isUpTop, rpid) => _htmlRenderCtr.onToggleTop(
|
|
||||||
index,
|
|
||||||
_htmlRenderCtr.oid,
|
|
||||||
_htmlRenderCtr.type,
|
|
||||||
isUpTop,
|
|
||||||
rpid,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: HttpError(
|
|
||||||
onReload: _htmlRenderCtr.onReload,
|
|
||||||
),
|
|
||||||
Error() => HttpError(
|
|
||||||
errMsg: loadingState.errMsg,
|
|
||||||
onReload: _htmlRenderCtr.onReload,
|
|
||||||
),
|
|
||||||
LoadingState() => throw UnimplementedError(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Container replyHeader() {
|
|
||||||
return Container(
|
|
||||||
height: 45,
|
|
||||||
padding: const EdgeInsets.only(left: 12, right: 6),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Text('回复'),
|
|
||||||
const Spacer(),
|
|
||||||
SizedBox(
|
|
||||||
height: 35,
|
|
||||||
child: TextButton.icon(
|
|
||||||
onPressed: () => _htmlRenderCtr.queryBySort(),
|
|
||||||
icon: const Icon(Icons.sort, size: 16),
|
|
||||||
label: Obx(
|
|
||||||
() => Text(
|
|
||||||
_htmlRenderCtr.sortType.value.label,
|
|
||||||
style: const TextStyle(fontSize: 13),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget get _buildHeader => Padding(
|
|
||||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 8),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
if (_htmlRenderCtr.mid != null) {
|
|
||||||
Get.toNamed('/member?mid=${_htmlRenderCtr.mid}');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
NetworkImgLayer(
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
type: 'avatar',
|
|
||||||
src: _htmlRenderCtr.response['avatar']!,
|
|
||||||
),
|
|
||||||
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(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget get _buildContent => SliverPadding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
||||||
sliver: Obx(
|
|
||||||
() => _htmlRenderCtr.loaded.value
|
|
||||||
? _htmlRenderCtr.response['isJsonContent'] == true
|
|
||||||
? SliverLayoutBuilder(
|
|
||||||
builder: (context, constraints) => articleContent(
|
|
||||||
context: context,
|
|
||||||
list: _htmlRenderCtr.response['content'],
|
|
||||||
callback: _getImageCallback,
|
|
||||||
maxWidth: constraints.crossAxisExtent,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: SliverToBoxAdapter(
|
|
||||||
child: LayoutBuilder(
|
|
||||||
builder: (context, constraints) => htmlRender(
|
|
||||||
context: context,
|
|
||||||
htmlContent: _htmlRenderCtr.response['content'],
|
|
||||||
constrainedWidth: constraints.maxWidth,
|
|
||||||
callback: _getImageCallback,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: SliverToBoxAdapter(child: const SizedBox()),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user