✨ Limit content and read more in posts
This commit is contained in:
parent
c00a018380
commit
12102bf527
@ -61,6 +61,7 @@ class _PostDetailScreenState extends State<PostDetailScreen> {
|
|||||||
item: item!,
|
item: item!,
|
||||||
isClickable: true,
|
isClickable: true,
|
||||||
isFullDate: true,
|
isFullDate: true,
|
||||||
|
isFullContent: true,
|
||||||
isShowReply: false,
|
isShowReply: false,
|
||||||
isContentSelectable: true,
|
isContentSelectable: true,
|
||||||
),
|
),
|
||||||
|
@ -361,4 +361,5 @@ const i18nEnglish = {
|
|||||||
'stickerUploaderName': 'Name',
|
'stickerUploaderName': 'Name',
|
||||||
'stickerUploaderNameHint':
|
'stickerUploaderNameHint':
|
||||||
'A human-friendly name given to the user in the sticker selection interface.',
|
'A human-friendly name given to the user in the sticker selection interface.',
|
||||||
|
'readMore': 'Read more',
|
||||||
};
|
};
|
||||||
|
@ -329,4 +329,5 @@ const i18nSimplifiedChinese = {
|
|||||||
'stickerUploaderAliasHint': '将会在输入时使用和贴图包前缀组成占位符。',
|
'stickerUploaderAliasHint': '将会在输入时使用和贴图包前缀组成占位符。',
|
||||||
'stickerUploaderName': '贴图名称',
|
'stickerUploaderName': '贴图名称',
|
||||||
'stickerUploaderNameHint': '在贴图选择界面提供给用户的人类友好名称。',
|
'stickerUploaderNameHint': '在贴图选择界面提供给用户的人类友好名称。',
|
||||||
|
'readMore': '阅读更多',
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:animations/animations.dart';
|
import 'package:animations/animations.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:get/get_utils/get_utils.dart';
|
import 'package:get/get_utils/get_utils.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
@ -23,6 +24,7 @@ class PostItem extends StatefulWidget {
|
|||||||
final bool isShowReply;
|
final bool isShowReply;
|
||||||
final bool isShowEmbed;
|
final bool isShowEmbed;
|
||||||
final bool isFullDate;
|
final bool isFullDate;
|
||||||
|
final bool isFullContent;
|
||||||
final bool isContentSelectable;
|
final bool isContentSelectable;
|
||||||
final String? attachmentParent;
|
final String? attachmentParent;
|
||||||
final Color? backgroundColor;
|
final Color? backgroundColor;
|
||||||
@ -36,6 +38,7 @@ class PostItem extends StatefulWidget {
|
|||||||
this.isShowReply = true,
|
this.isShowReply = true,
|
||||||
this.isShowEmbed = true,
|
this.isShowEmbed = true,
|
||||||
this.isFullDate = false,
|
this.isFullDate = false,
|
||||||
|
this.isFullContent = false,
|
||||||
this.isContentSelectable = false,
|
this.isContentSelectable = false,
|
||||||
this.attachmentParent,
|
this.attachmentParent,
|
||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
@ -256,6 +259,8 @@ class _PostItemState extends State<PostItem> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double _contentHeight = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final List<int> attachments = item.body['attachments'] is List
|
final List<int> attachments = item.body['attachments'] is List
|
||||||
@ -327,11 +332,31 @@ class _PostItemState extends State<PostItem> {
|
|||||||
_buildHeader(),
|
_buildHeader(),
|
||||||
SizedContainer(
|
SizedContainer(
|
||||||
maxWidth: 640,
|
maxWidth: 640,
|
||||||
child: MarkdownTextContent(
|
maxHeight: widget.isFullContent ? double.infinity : 320,
|
||||||
content: item.body['content'],
|
child: _MeasureSize(
|
||||||
isSelectable: widget.isContentSelectable,
|
onChange: (size) {
|
||||||
).paddingOnly(left: 12, right: 8),
|
_contentHeight = size.height;
|
||||||
|
},
|
||||||
|
child: MarkdownTextContent(
|
||||||
|
content: item.body['content'],
|
||||||
|
isSelectable: widget.isContentSelectable,
|
||||||
|
).paddingOnly(left: 12, right: 8),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
if (_contentHeight >= 320 &&
|
||||||
|
widget.isClickable &&
|
||||||
|
!widget.isFullContent)
|
||||||
|
InkWell(
|
||||||
|
child: Text(
|
||||||
|
'readMore'.tr,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
openContainer();
|
||||||
|
},
|
||||||
|
).paddingOnly(left: 12, top: 4),
|
||||||
if (widget.item.replyTo != null && widget.isShowEmbed)
|
if (widget.item.replyTo != null && widget.isShowEmbed)
|
||||||
_buildReply(context).paddingOnly(top: 4),
|
_buildReply(context).paddingOnly(top: 4),
|
||||||
if (widget.item.repostTo != null && widget.isShowEmbed)
|
if (widget.item.repostTo != null && widget.isShowEmbed)
|
||||||
@ -388,3 +413,46 @@ class _PostItemState extends State<PostItem> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef _OnWidgetSizeChange = void Function(Size size);
|
||||||
|
|
||||||
|
class _MeasureSizeRenderObject extends RenderProxyBox {
|
||||||
|
Size? oldSize;
|
||||||
|
_OnWidgetSizeChange onChange;
|
||||||
|
|
||||||
|
_MeasureSizeRenderObject(this.onChange);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void performLayout() {
|
||||||
|
super.performLayout();
|
||||||
|
|
||||||
|
Size newSize = child!.size;
|
||||||
|
if (oldSize == newSize) return;
|
||||||
|
|
||||||
|
oldSize = newSize;
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
onChange(newSize);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MeasureSize extends SingleChildRenderObjectWidget {
|
||||||
|
final _OnWidgetSizeChange onChange;
|
||||||
|
|
||||||
|
const _MeasureSize({
|
||||||
|
super.key,
|
||||||
|
required this.onChange,
|
||||||
|
required Widget super.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
RenderObject createRenderObject(BuildContext context) {
|
||||||
|
return _MeasureSizeRenderObject(onChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void updateRenderObject(
|
||||||
|
BuildContext context, covariant _MeasureSizeRenderObject renderObject) {
|
||||||
|
renderObject.onChange = onChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,11 +3,13 @@ import 'package:flutter/material.dart';
|
|||||||
class SizedContainer extends StatelessWidget {
|
class SizedContainer extends StatelessWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final double maxWidth;
|
final double maxWidth;
|
||||||
|
final double maxHeight;
|
||||||
|
|
||||||
const SizedContainer({
|
const SizedContainer({
|
||||||
super.key,
|
super.key,
|
||||||
required this.child,
|
required this.child,
|
||||||
this.maxWidth = 720,
|
this.maxWidth = 720,
|
||||||
|
this.maxHeight = double.infinity,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -15,7 +17,7 @@ class SizedContainer extends StatelessWidget {
|
|||||||
return Align(
|
return Align(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: BoxConstraints(maxWidth: maxWidth),
|
constraints: BoxConstraints(maxWidth: maxWidth, maxHeight: maxHeight),
|
||||||
child: child,
|
child: child,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user