Skip to content

Commit

Permalink
feat(*): Update quoted text style
Browse files Browse the repository at this point in the history
This commit updated the quoted text style app wide. Before this commit
all the quoted text in notice and post are wrapped in a card with more
elevation. From this commit on, these quoted text are surrounded by icon
which looks like double quote symbol.
Added `QuotedText` widget with two ways to construct:
* Construct from normal `String` type text, will wrap in a `RichText`.
* Construct from an `InlineSpan`, will be wrapped in a row with two
  `RichText` to ensure the visible style.
  • Loading branch information
realth000 committed Feb 20, 2024
1 parent 426cfed commit 0090dfe
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 38 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- 新增显示帖子的悬赏状态及对应的最佳答案。
- 新增支持编辑已发布的帖子和回复。
* 楼层右下角菜单 -> 编辑。
* 一些附加选项可能需要文本编辑器支持,目前可能不完全支持。
* 暂不支持设置阅读权限和售价。
- 楼层右下角菜单 -> 编辑。
- 一些附加选项可能需要文本编辑器支持,目前可能不完全支持。
- 暂不支持设置阅读权限和售价。
- 新增解析批量评分类型的提醒。
- 在通知页内显示已有x条相同通知被忽略。
- 支持筛选积分变更历史。
Expand All @@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Changed

- 现在引用的文本用双引号包裹,而不是在一块更“高”的Card里。
- 涉及评分通知、帖子楼层内引用的文本。
- 高亮显示通知卡片中的帖子标题和积分变动。
- internal: 支持flutter 3.19。
- internal: 去除安卓gradle构建脚本中标记为弃用的部分。
Expand Down
9 changes: 2 additions & 7 deletions lib/packages/html_muncher/lib/src/html_muncher.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:collection/collection.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:tsdm_client/constants/layout.dart';
import 'package:tsdm_client/extensions/build_context.dart';
import 'package:tsdm_client/extensions/universal_html.dart';
import 'package:tsdm_client/packages/html_muncher/lib/src/types.dart';
Expand All @@ -15,6 +14,7 @@ import 'package:tsdm_client/widgets/card/lock_card/locked_card.dart';
import 'package:tsdm_client/widgets/card/review_card.dart';
import 'package:tsdm_client/widgets/card/spoiler_card.dart';
import 'package:tsdm_client/widgets/network_indicator_image.dart';
import 'package:tsdm_client/widgets/quoted_text.dart';
import 'package:universal_html/html.dart' as uh;

/// Munch the html node [rootElement] and its children nodes into a flutter
Expand Down Expand Up @@ -408,12 +408,7 @@ class Muncher {
return TextSpan(
children: [
WidgetSpan(
child: Card(
child: Padding(
padding: edgeInsetsL15T15R15B15,
child: RichText(text: ret),
),
),
child: QuotedText.rich(ret),
),
const TextSpan(text: '\n'),
],
Expand Down
25 changes: 8 additions & 17 deletions lib/widgets/card/notice_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:tsdm_client/features/notification/models/notice.dart';
import 'package:tsdm_client/generated/i18n/strings.g.dart';
import 'package:tsdm_client/routes/screen_paths.dart';
import 'package:tsdm_client/widgets/cached_image/cached_image_provider.dart';
import 'package:tsdm_client/widgets/quoted_text.dart';
import 'package:tsdm_client/widgets/single_line_text.dart';

/// Widget to show a single [Notice].
Expand Down Expand Up @@ -71,14 +72,10 @@ class NoticeCard extends StatelessWidget {
),
),
),
if (notice.quotedMessage?.isNotEmpty ?? false)
Card(
elevation: 2,
child: Padding(
padding: edgeInsetsL15T15R15B15,
child: Text(notice.quotedMessage!),
),
),
if (notice.quotedMessage?.isNotEmpty ?? false) ...[
sizedBoxW5H5,
QuotedText(notice.quotedMessage ?? ''),
],
if (notice.taskId != null) sizedBoxW5H5,
if (notice.taskId != null)
Text(
Expand All @@ -89,16 +86,10 @@ class NoticeCard extends StatelessWidget {
),
NoticeType.mention => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
children: <Widget>[
Text(context.t.noticePage.noticeTab.mentionBody),
Card(
elevation: 2,
child: Padding(
padding: edgeInsetsL15T15R15B15,
child: Text(notice.quotedMessage ?? ''),
),
),
],
QuotedText(notice.quotedMessage ?? ''),
].insertBetween(sizedBoxW5H5),
),
NoticeType.invite => Text.rich(
context.t.noticePage.noticeTab.inviteBody(
Expand Down
13 changes: 2 additions & 11 deletions lib/widgets/card/thread_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:tsdm_client/shared/models/normal_thread.dart';
import 'package:tsdm_client/shared/models/thread_type.dart';
import 'package:tsdm_client/shared/models/user.dart';
import 'package:tsdm_client/themes/widget_themes.dart';
import 'package:tsdm_client/widgets/quoted_text.dart';
import 'package:tsdm_client/widgets/single_line_text.dart';

class _CardLayout extends StatelessWidget {
Expand Down Expand Up @@ -148,17 +149,7 @@ class _CardLayout extends StatelessWidget {
),
if (quotedMessage != null)
Row(
children: [
Expanded(
child: Card(
elevation: 2,
child: Padding(
padding: edgeInsetsL15T15R15B15,
child: Text(quotedMessage!),
),
),
),
],
children: [Expanded(child: QuotedText(quotedMessage ?? ''))],
),
if (infoWidgetList.isNotEmpty)
Padding(
Expand Down
89 changes: 89 additions & 0 deletions lib/widgets/quoted_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:tsdm_client/constants/layout.dart';

/// Widget to show some quoted text.
class QuotedText extends StatelessWidget {
/// Construct from [String] [text].
const QuotedText(this.text, {super.key}) : span = null;

/// Construct from an [InlineSpan] span.
const QuotedText.rich(this.span, {super.key}) : text = null;

/// Text to show in quoted style.
final String? text;

/// Span to show in quoted style.
final InlineSpan? span;

@override
Widget build(BuildContext context) {
final quotedColor = Theme.of(context).colorScheme.tertiary;
final quotedStyle =
Theme.of(context).textTheme.bodyMedium?.copyWith(color: quotedColor);

final iconHead = Transform.rotate(
angle: 180 * pi / 180,
child: Icon(Icons.format_quote_rounded, size: 28, color: quotedColor),
);

final spanHead = TextSpan(children: [WidgetSpan(child: iconHead)]);

final iconTail =
Icon(Icons.format_quote_rounded, size: 28, color: quotedColor);

final spanTail = TextSpan(children: [WidgetSpan(child: iconTail)]);

if (text != null) {
return Text.rich(
TextSpan(children: [spanHead, TextSpan(text: ' $text '), spanTail]),
);
}

if (span != null) {
// Because we want to let the start quoted icon lay on the left of
// the content span, but rich text widgets and span widgets do not
// provide such api, we have to wrap the head and the rest of contents
// in two rich text and put in a row.
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
WidgetSpan(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
iconHead,
],
),
),
),
sizedBoxW5H5,
Expanded(
child: Text.rich(
TextSpan(
children: [
// Add a line feed to ensure the child content is lower than
// start quote icon in vertical direction.
TextSpan(text: '\n', style: quotedStyle, children: [span!]),
WidgetSpan(
child: Row(
children: [
const Spacer(),
iconTail,
],
),
),
],
),
),
),
],
);
}

// Impossible.
return Container();
}
}

0 comments on commit 0090dfe

Please sign in to comment.