From f8bed6946e5f4180e6f77857bfd5c0e2d5e384c8 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 7 Jul 2024 03:02:10 +0800 Subject: [PATCH] :lipstick: Better posting page --- lib/screens/feed.dart | 16 +- lib/screens/posts/post_publish.dart | 243 +++++++++++++--------------- 2 files changed, 128 insertions(+), 131 deletions(-) diff --git a/lib/screens/feed.dart b/lib/screens/feed.dart index 3a48404..04c7906 100644 --- a/lib/screens/feed.dart +++ b/lib/screens/feed.dart @@ -68,7 +68,11 @@ class _FeedScreenState extends State { actions: [ const BackgroundStateWidget(), const NotificationButton(), - const FeedCreationButton(), + FeedCreationButton( + onCreated: () { + _pagingController.refresh(); + }, + ), SizedBox( width: SolianTheme.isLargeScreen(context) ? 8 : 16, ), @@ -84,7 +88,9 @@ class _FeedScreenState extends State { } class FeedCreationButton extends StatelessWidget { - const FeedCreationButton({super.key}); + final Function? onCreated; + + const FeedCreationButton({super.key, this.onCreated}); @override Widget build(BuildContext context) { @@ -97,7 +103,11 @@ class FeedCreationButton extends StatelessWidget { return IconButton( icon: const Icon(Icons.add_circle), onPressed: () { - AppRouter.instance.pushNamed('postPublishing'); + AppRouter.instance.pushNamed('postPublishing').then((val) { + if (val == true && onCreated != null) { + onCreated!(); + } + }); }, ); } diff --git a/lib/screens/posts/post_publish.dart b/lib/screens/posts/post_publish.dart index 686447e..55afdcc 100644 --- a/lib/screens/posts/post_publish.dart +++ b/lib/screens/posts/post_publish.dart @@ -137,139 +137,126 @@ class _PostPublishingScreenState extends State { ), body: SafeArea( top: false, - child: Column( + child: Stack( children: [ - if (_isBusy) const LinearProgressIndicator().animate().scaleX(), - if (widget.edit != null) - MaterialBanner( - leading: const Icon(Icons.edit), - leadingPadding: const EdgeInsets.only(left: 10, right: 20), - dividerColor: Colors.transparent, - content: Text('postEditingNotify'.tr), - actions: notifyBannerActions, - ), - if (widget.reply != null) - Container( - color: Theme.of(context).colorScheme.surfaceContainerLow, - child: Column( - children: [ - MaterialBanner( - leading: const FaIcon( - FontAwesomeIcons.reply, - size: 18, - ), - leadingPadding: - const EdgeInsets.only(left: 10, right: 20), - backgroundColor: Colors.transparent, - dividerColor: Colors.transparent, - content: Text( - 'postReplyingNotify'.trParams( - {'username': '@${widget.reply!.author.name}'}, - ), - ), - actions: notifyBannerActions, - ), - const Divider(thickness: 0.3, height: 0.3), - Container( - constraints: const BoxConstraints(maxHeight: 280), - child: SingleChildScrollView( - child: PostItem( - item: widget.reply!, - isReactable: false, - ), - ), - ), - ], - ), - ), - if (widget.repost != null) - Container( - color: Theme.of(context).colorScheme.surfaceContainerLow, - child: Column( - children: [ - MaterialBanner( - leading: const FaIcon( - FontAwesomeIcons.retweet, - size: 18, - ), - leadingPadding: - const EdgeInsets.only(left: 10, right: 20), - dividerColor: Colors.transparent, - content: Text( - 'postRepostingNotify'.trParams( - {'username': '@${widget.repost!.author.name}'}, - ), - ), - actions: notifyBannerActions, - ), - const Divider(thickness: 0.3, height: 0.3), - Container( - constraints: const BoxConstraints(maxHeight: 280), - child: SingleChildScrollView( - child: PostItem( - item: widget.repost!, - isReactable: false, - ), - ), - ), - ], - ), - ), - FutureBuilder( - future: auth.getProfile(), - builder: (context, snapshot) { - if (snapshot.hasData) { - return ListTile( - leading: AccountAvatar( - content: snapshot.data?.body!['avatar'], radius: 22), - title: Text(snapshot.data?.body!['nick']), - subtitle: Text('postIdentityNotify'.tr), - ); - } else { - return Container(); - } - }, - ), - if (widget.realm != null) - MaterialBanner( - leading: const Icon(Icons.group), - leadingPadding: const EdgeInsets.only(left: 10, right: 20), - dividerColor: Colors.transparent, - content: Text( - 'postInRealmNotify' - .trParams({'realm': '#${widget.realm!.alias}'}), - ), - actions: notifyBannerActions, - ), - const Divider(thickness: 0.3, height: 0.3).paddingOnly(bottom: 8), - Expanded( - child: Container( - padding: - const EdgeInsets.symmetric(horizontal: 16, vertical: 8), - child: TextField( - maxLines: null, - autofocus: true, - autocorrect: true, - keyboardType: TextInputType.multiline, - controller: _contentController, - decoration: InputDecoration.collapsed( - hintText: 'postContentPlaceholder'.tr, + ListView( + children: [ + if (_isBusy) + const LinearProgressIndicator().animate().scaleX(), + if (widget.edit != null) + MaterialBanner( + leading: const Icon(Icons.edit), + leadingPadding: + const EdgeInsets.only(left: 10, right: 20), + dividerColor: Colors.transparent, + content: Text('postEditingNotify'.tr), + actions: notifyBannerActions, ), - onTapOutside: (_) => - FocusManager.instance.primaryFocus?.unfocus(), + if (widget.reply != null) + ExpansionTile( + leading: const FaIcon( + FontAwesomeIcons.reply, + size: 18, + ).paddingOnly(left: 2), + title: Text('postReplyingNotify'.trParams( + {'username': '@${widget.reply!.author.name}'}, + )), + collapsedBackgroundColor: + Theme.of(context).colorScheme.surfaceContainer, + children: [ + PostItem( + item: widget.reply!, + isReactable: false, + ).paddingOnly(bottom: 8), + ], + ), + if (widget.repost != null) + ExpansionTile( + leading: const FaIcon( + FontAwesomeIcons.retweet, + size: 18, + ).paddingOnly(left: 2), + title: Text('postRepostingNotify'.trParams( + {'username': '@${widget.repost!.author.name}'}, + )), + collapsedBackgroundColor: + Theme.of(context).colorScheme.surfaceContainer, + children: [ + PostItem( + item: widget.repost!, + isReactable: false, + ).paddingOnly(bottom: 8), + ], + ), + FutureBuilder( + future: auth.getProfile(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return ListTile( + leading: AccountAvatar( + content: snapshot.data?.body!['avatar'], + radius: 22), + title: Text(snapshot.data?.body!['nick']), + subtitle: Text('postIdentityNotify'.tr), + ); + } else { + return Container(); + } + }, ), - ), + if (widget.realm != null) + MaterialBanner( + leading: const Icon(Icons.group), + leadingPadding: + const EdgeInsets.only(left: 10, right: 20), + dividerColor: Colors.transparent, + content: Text( + 'postInRealmNotify' + .trParams({'realm': '#${widget.realm!.alias}'}), + ), + actions: notifyBannerActions, + ), + const Divider(thickness: 0.3, height: 0.3) + .paddingOnly(bottom: 8), + Container( + padding: + const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + child: TextField( + maxLines: null, + autofocus: true, + autocorrect: true, + keyboardType: TextInputType.multiline, + controller: _contentController, + decoration: InputDecoration.collapsed( + hintText: 'postContentPlaceholder'.tr, + ), + onTapOutside: (_) => + FocusManager.instance.primaryFocus?.unfocus(), + ), + ), + ], ), - const Divider(thickness: 0.3, height: 0.3), - SizedBox( - height: 56, - child: Row( + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Column( children: [ - TextButton( - style: TextButton.styleFrom(shape: const CircleBorder()), - child: const Icon(Icons.camera_alt), - onPressed: () => showAttachments(), - ) + const Divider(thickness: 0.3, height: 0.3), + SizedBox( + height: 56, + child: Row( + children: [ + TextButton( + style: TextButton.styleFrom( + shape: const CircleBorder(), + ), + child: const Icon(Icons.camera_alt), + onPressed: () => showAttachments(), + ) + ], + ), + ), ], ), ),