From 1aa45dd9f140ff784e429981320d71295201c2ec Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 4 Aug 2025 17:36:04 +0800 Subject: [PATCH] :bug: Fix bottom sheet didn't avoid keyboard --- lib/widgets/content/sheet.dart | 1 + lib/widgets/post/post_item.dart | 10 +- lib/widgets/share/share_sheet.dart | 249 +++++++++++++---------------- 3 files changed, 121 insertions(+), 139 deletions(-) diff --git a/lib/widgets/content/sheet.dart b/lib/widgets/content/sheet.dart index 13fa725..ee121ab 100644 --- a/lib/widgets/content/sheet.dart +++ b/lib/widgets/content/sheet.dart @@ -33,6 +33,7 @@ class SheetScaffold extends StatelessWidget { ); return Container( + padding: MediaQuery.of(context).viewInsets, constraints: BoxConstraints( maxHeight: height ?? MediaQuery.of(context).size.height * heightFactor, ), diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 5b08614..212e97c 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -864,22 +864,22 @@ class PostReplyPreview extends HookConsumerWidget { : featuredReply!.when( data: (value) => Row( - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, spacing: 8, children: [ ProfilePictureWidget( - file: value!.publisher.picture, + file: value?.publisher.picture, radius: 12, ).padding(top: 4), - if (value.content?.isNotEmpty ?? false) + if (value?.content?.isNotEmpty ?? false) Expanded( - child: MarkdownTextContent(content: value.content!), + child: MarkdownTextContent(content: value!.content!), ) else Expanded( child: Text( 'postHasAttachments', - ).plural(value.attachments.length), + ).plural(value?.attachments.length ?? 0), ), ], ), diff --git a/lib/widgets/share/share_sheet.dart b/lib/widgets/share/share_sheet.dart index c4c107c..693b6c1 100644 --- a/lib/widgets/share/share_sheet.dart +++ b/lib/widgets/share/share_sheet.dart @@ -284,7 +284,7 @@ class _ShareSheetState extends ConsumerState { // Send message to chat room await apiClient.post( - '/chat/${chatRoom.id}/messages', + '/sphere/chat/${chatRoom.id}/messages', data: {'content': content, 'attachments_id': attachmentIds, 'meta': {}}, ); @@ -328,12 +328,7 @@ class _ShareSheetState extends ConsumerState { } } catch (e) { if (mounted) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text('Failed to share to chat: $e'), - backgroundColor: Theme.of(context).colorScheme.error, - ), - ); + showSnackBar('Failed to share to chat: $e'); } } finally { if (mounted) { @@ -405,151 +400,137 @@ class _ShareSheetState extends ConsumerState { children: [ // Share options with keyboard avoidance Expanded( - child: AnimatedPadding( - duration: const Duration(milliseconds: 300), - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom, - ), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Content preview - Container( - margin: const EdgeInsets.all(16), - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: - Theme.of( - context, - ).colorScheme.surfaceContainerHighest, - borderRadius: BorderRadius.circular(12), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'contentToShare'.tr(), - style: Theme.of( - context, - ).textTheme.labelMedium?.copyWith( - color: - Theme.of( - context, - ).colorScheme.onSurfaceVariant, - ), - ), - const SizedBox(height: 8), - _ContentPreview(content: widget.content), - ], - ), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Content preview + Container( + margin: const EdgeInsets.all(16), + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: + Theme.of(context).colorScheme.surfaceContainerHighest, + borderRadius: BorderRadius.circular(12), ), - // Quick actions row (horizontally scrollable) - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'quickActions'.tr(), - style: Theme.of( - context, - ).textTheme.titleSmall?.copyWith( - color: - Theme.of( - context, - ).colorScheme.onSurfaceVariant, - ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'contentToShare'.tr(), + style: Theme.of( + context, + ).textTheme.labelMedium?.copyWith( + color: + Theme.of(context).colorScheme.onSurfaceVariant, ), - const SizedBox(height: 12), - SizedBox( - height: 80, - child: ListView( - scrollDirection: Axis.horizontal, - children: [ - _CompactShareOption( - icon: Symbols.post_add, - title: 'post'.tr(), - onTap: _isLoading ? null : _shareToPost, - ), + ), + const SizedBox(height: 8), + _ContentPreview(content: widget.content), + ], + ), + ), + // Quick actions row (horizontally scrollable) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'quickActions'.tr(), + style: Theme.of( + context, + ).textTheme.titleSmall?.copyWith( + color: + Theme.of(context).colorScheme.onSurfaceVariant, + ), + ), + const SizedBox(height: 12), + SizedBox( + height: 80, + child: ListView( + scrollDirection: Axis.horizontal, + children: [ + _CompactShareOption( + icon: Symbols.post_add, + title: 'post'.tr(), + onTap: _isLoading ? null : _shareToPost, + ), + const SizedBox(width: 12), + _CompactShareOption( + icon: Symbols.content_copy, + title: 'copy'.tr(), + onTap: _isLoading ? null : _copyToClipboard, + ), + if (widget.toSystem) ...[ const SizedBox(width: 12), _CompactShareOption( - icon: Symbols.content_copy, - title: 'copy'.tr(), - onTap: _isLoading ? null : _copyToClipboard, + icon: Symbols.share, + title: 'share'.tr(), + onTap: _isLoading ? null : _shareToSystem, ), - if (widget.toSystem) ...[ - const SizedBox(width: 12), - _CompactShareOption( - icon: Symbols.share, - title: 'share'.tr(), - onTap: _isLoading ? null : _shareToSystem, - ), - ], ], - ), + ], ), - ], - ), + ), + ], ), + ), - const SizedBox(height: 24), + const SizedBox(height: 24), - // Chat section - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'sendToChat'.tr(), - style: Theme.of( - context, - ).textTheme.titleSmall?.copyWith( - color: - Theme.of( - context, - ).colorScheme.onSurfaceVariant, - ), + // Chat section + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'sendToChat'.tr(), + style: Theme.of( + context, + ).textTheme.titleSmall?.copyWith( + color: + Theme.of(context).colorScheme.onSurfaceVariant, ), - const SizedBox(height: 12), + ), + const SizedBox(height: 12), - // Additional message input - Container( - margin: const EdgeInsets.only(bottom: 16), - child: TextField( - controller: _messageController, - decoration: InputDecoration( - hintText: 'addAdditionalMessage'.tr(), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - ), - contentPadding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 12, - ), + // Additional message input + Container( + margin: const EdgeInsets.only(bottom: 16), + child: TextField( + controller: _messageController, + decoration: InputDecoration( + hintText: 'addAdditionalMessage'.tr(), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(12), + ), + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 12, ), - onTapOutside: - (_) => - FocusManager.instance.primaryFocus - ?.unfocus(), - maxLines: 3, - minLines: 1, - enabled: !_isLoading, ), + onTapOutside: + (_) => + FocusManager.instance.primaryFocus + ?.unfocus(), + maxLines: 3, + minLines: 1, + enabled: !_isLoading, ), + ), - _ChatRoomsList( - onChatSelected: - _isLoading ? null : _shareToSpecificChat, - ), - ], - ), + _ChatRoomsList( + onChatSelected: + _isLoading ? null : _shareToSpecificChat, + ), + ], ), + ), - const SizedBox(height: 16), - ], - ), + const SizedBox(height: 16), + ], ), ), ),