mod: reply save layout
This commit is contained in:
@ -1,6 +1,5 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:appscheme/appscheme.dart';
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@ -46,7 +45,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
final bool? showReplyRow;
|
final bool? showReplyRow;
|
||||||
final Function? replyReply;
|
final Function? replyReply;
|
||||||
final ReplyType? replyType;
|
final ReplyType? replyType;
|
||||||
final bool? replySave;
|
final bool replySave;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -56,7 +55,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
child: InkWell(
|
child: InkWell(
|
||||||
// 点击整个评论区 评论详情/回复
|
// 点击整个评论区 评论详情/回复
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (replySave!) {
|
if (replySave) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
feedBack();
|
feedBack();
|
||||||
@ -65,7 +64,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
if (replySave!) {
|
if (replySave) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
feedBack();
|
feedBack();
|
||||||
@ -238,53 +237,32 @@ class ReplyItem extends StatelessWidget {
|
|||||||
// title
|
// title
|
||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.only(top: 10, left: 45, right: 6, bottom: 4),
|
margin: const EdgeInsets.only(top: 10, left: 45, right: 6, bottom: 4),
|
||||||
child: LayoutBuilder(
|
child: !replySave
|
||||||
builder: (BuildContext context, BoxConstraints boxConstraints) {
|
? LayoutBuilder(builder:
|
||||||
String text = replyItem?.content?.message ?? '';
|
(BuildContext context, BoxConstraints boxConstraints) {
|
||||||
bool didExceedMaxLines = false;
|
String text = replyItem?.content?.message ?? '';
|
||||||
final double maxWidth = boxConstraints.maxWidth;
|
bool didExceedMaxLines = false;
|
||||||
TextPainter? textPainter;
|
final double maxWidth = boxConstraints.maxWidth;
|
||||||
final int maxLines =
|
TextPainter? textPainter;
|
||||||
replyItem!.content!.isText! && replyLevel == '1' ? 6 : 999;
|
final int maxLines =
|
||||||
try {
|
replyItem!.content!.isText! && replyLevel == '1'
|
||||||
textPainter = TextPainter(
|
? 6
|
||||||
text: TextSpan(text: text),
|
: 999;
|
||||||
maxLines: maxLines,
|
try {
|
||||||
textDirection: Directionality.of(context),
|
textPainter = TextPainter(
|
||||||
);
|
text: TextSpan(text: text),
|
||||||
textPainter.layout(maxWidth: maxWidth);
|
maxLines: maxLines,
|
||||||
didExceedMaxLines = textPainter.didExceedMaxLines;
|
textDirection: Directionality.of(context),
|
||||||
} catch (e) {
|
);
|
||||||
debugPrint('Error while measuring text: $e');
|
textPainter.layout(maxWidth: maxWidth);
|
||||||
didExceedMaxLines = false;
|
didExceedMaxLines = textPainter.didExceedMaxLines;
|
||||||
}
|
} catch (e) {
|
||||||
return Text.rich(
|
debugPrint('Error while measuring text: $e');
|
||||||
style: const TextStyle(height: 1.75),
|
didExceedMaxLines = false;
|
||||||
TextSpan(
|
}
|
||||||
children: [
|
return replyContent(context, didExceedMaxLines, textPainter);
|
||||||
if (replyItem!.isTop!)
|
})
|
||||||
const WidgetSpan(
|
: replyContent(context, false, null),
|
||||||
alignment: PlaceholderAlignment.top,
|
|
||||||
child: PBadge(
|
|
||||||
text: 'TOP',
|
|
||||||
size: 'small',
|
|
||||||
stack: 'normal',
|
|
||||||
type: 'line',
|
|
||||||
fs: 9,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
buildContent(
|
|
||||||
context,
|
|
||||||
replyItem!,
|
|
||||||
replyReply,
|
|
||||||
null,
|
|
||||||
didExceedMaxLines,
|
|
||||||
textPainter,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
// 操作区域
|
// 操作区域
|
||||||
bottonAction(context, replyItem!.replyControl, replySave),
|
bottonAction(context, replyItem!.replyControl, replySave),
|
||||||
@ -307,6 +285,36 @@ class ReplyItem extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget replyContent(
|
||||||
|
BuildContext context, bool? didExceedMaxLines, TextPainter? textPainter) {
|
||||||
|
return Text.rich(
|
||||||
|
style: const TextStyle(height: 1.75),
|
||||||
|
TextSpan(
|
||||||
|
children: [
|
||||||
|
if (replyItem!.isTop!)
|
||||||
|
const WidgetSpan(
|
||||||
|
alignment: PlaceholderAlignment.top,
|
||||||
|
child: PBadge(
|
||||||
|
text: 'TOP',
|
||||||
|
size: 'small',
|
||||||
|
stack: 'normal',
|
||||||
|
type: 'line',
|
||||||
|
fs: 9,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
buildContent(
|
||||||
|
context,
|
||||||
|
replyItem!,
|
||||||
|
replyReply,
|
||||||
|
null,
|
||||||
|
didExceedMaxLines ?? false,
|
||||||
|
textPainter,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 感谢、回复、复制
|
// 感谢、回复、复制
|
||||||
Widget bottonAction(BuildContext context, replyControl, replySave) {
|
Widget bottonAction(BuildContext context, replyControl, replySave) {
|
||||||
ColorScheme colorScheme = Theme.of(context).colorScheme;
|
ColorScheme colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|||||||
Reference in New Issue
Block a user