From 7332f68d9ca6b470692afc6c4298ecfeafe35d1b Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 16 Aug 2024 00:52:36 +0800 Subject: [PATCH] :sparkles: Live preview of post editor --- lib/screens/posts/post_editor.dart | 65 ++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/lib/screens/posts/post_editor.dart b/lib/screens/posts/post_editor.dart index ea04d90..7c4e81d 100644 --- a/lib/screens/posts/post_editor.dart +++ b/lib/screens/posts/post_editor.dart @@ -14,6 +14,7 @@ import 'package:solian/router.dart'; import 'package:solian/theme.dart'; import 'package:solian/widgets/app_bar_leading.dart'; import 'package:solian/widgets/app_bar_title.dart'; +import 'package:solian/widgets/markdown_text_content.dart'; import 'package:solian/widgets/posts/post_item.dart'; import 'package:badges/badges.dart' as badges; @@ -90,6 +91,7 @@ class _PostPublishScreenState extends State { context.showErrorDialog(resp.bodyString); } else { _editorController.localClear(); + _editorController.currentClear(); AppRouter.instance.pop(resp.body); } @@ -254,30 +256,51 @@ class _PostPublishScreenState extends State { ], ), Expanded( - child: ListView( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (_isBusy) - const LinearProgressIndicator().animate().scaleX(), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 8, - ), - child: TextField( - maxLines: null, - autofocus: true, - autocorrect: true, - keyboardType: TextInputType.multiline, - controller: _editorController.contentController, - focusNode: _contentFocusNode, - decoration: InputDecoration.collapsed( - hintText: 'postContentPlaceholder'.tr, - ), - onTapOutside: (_) => - FocusManager.instance.primaryFocus?.unfocus(), + Expanded( + child: ListView( + children: [ + if (_isBusy) + const LinearProgressIndicator().animate().scaleX(), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 8, + ), + child: TextField( + maxLines: null, + autofocus: true, + autocorrect: true, + keyboardType: TextInputType.multiline, + controller: _editorController.contentController, + focusNode: _contentFocusNode, + decoration: InputDecoration.collapsed( + hintText: 'postContentPlaceholder'.tr, + ), + onTapOutside: (_) => + FocusManager.instance.primaryFocus?.unfocus(), + ), + ), + const SizedBox(height: 120) + ], ), ), - const SizedBox(height: 120) + if (SolianTheme.isLargeScreen(context)) + const VerticalDivider(width: 0.3, thickness: 0.3) + .paddingSymmetric( + horizontal: 8, + ), + if (SolianTheme.isLargeScreen(context)) + Expanded( + child: SingleChildScrollView( + child: MarkdownTextContent( + content: _editorController.contentController.text, + parentId: 'post-editor-preview', + ).paddingOnly(top: 8), + ), + ), ], ), ),