From e0024ed123653619fe9283d1558e50a10ba1f9e5 Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Wed, 21 Oct 2026 13:36:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(player):=20=E8=AF=84=E8=AE=BA=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=BC=B9=E7=AA=97=E6=94=B9=E4=B8=BA=E7=B4=A7=E5=87=91?= =?UTF-8?q?=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/comment_composer_sheet.dart | 107 ++++++++---------- test/comment/drama_comments_sheet_test.dart | 10 +- 2 files changed, 55 insertions(+), 62 deletions(-) diff --git a/lib/pages/player/widgets/comment_composer_sheet.dart b/lib/pages/player/widgets/comment_composer_sheet.dart index 7ef0c89..7d43806 100644 --- a/lib/pages/player/widgets/comment_composer_sheet.dart +++ b/lib/pages/player/widgets/comment_composer_sheet.dart @@ -147,13 +147,6 @@ class _CommentComposerSheetState extends State @override Widget build(BuildContext context) { - final screenHeight = MediaQuery.sizeOf(context).height; - final halfHeight = (screenHeight * 0.5).roundToDouble(); - final maxHeight = math.max( - 0.0, - screenHeight - MediaQuery.paddingOf(context).top, - ); - final sheetHeight = math.min(halfHeight, maxHeight); final keyboardHeight = _keyboardHeight(context); final l10n = AppLocalizations.of(context)!; final signedIn = context.watch().isSignedIn; @@ -167,7 +160,7 @@ class _CommentComposerSheetState extends State padding: EdgeInsets.only(bottom: keyboardHeight), child: SizedBox( key: const Key('comment-composer-sheet'), - height: sheetHeight, + width: double.infinity, child: Material( color: AppColors.card, clipBehavior: Clip.antiAlias, @@ -177,9 +170,10 @@ class _CommentComposerSheetState extends State child: SafeArea( top: false, child: Padding( - padding: const EdgeInsets.fromLTRB(16, 16, 16, 12), + padding: const EdgeInsets.fromLTRB(16, 12, 16, 12), child: TextFieldTapRegion( child: Column( + mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ if (widget.replyTo != null) @@ -197,57 +191,52 @@ class _CommentComposerSheetState extends State ), ), ), - Expanded( - child: Align( - alignment: Alignment.topCenter, - child: Container( - decoration: BoxDecoration( - color: AppColors.commentInput, - borderRadius: BorderRadius.circular(_inputRadius), - ), - child: TextField( - key: const Key('comment-composer-input'), - autofocus: true, - controller: _input, - focusNode: _inputFocus, - readOnly: !signedIn, - canRequestFocus: signedIn, - minLines: 1, - maxLines: 4, - maxLength: _maxCommentLength, - textAlignVertical: multiline - ? TextAlignVertical.top - : TextAlignVertical.center, - style: TextStyle( - color: AppColors.cream, - fontSize: 15, - height: multiline ? 1.4 : null, - ), - cursorColor: AppColors.blue, - decoration: InputDecoration( - hintText: signedIn - ? l10n.writeComment - : l10n.commentLoginHint, - hintStyle: const TextStyle( - color: AppColors.muted, - fontSize: 14, - ), - counterText: '', - contentPadding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 12, - ), - border: InputBorder.none, - enabledBorder: InputBorder.none, - focusedBorder: InputBorder.none, - ), - onTap: signedIn ? null : _authenticate, - onTapOutside: (_) { - _inputFocus.unfocus(); - _closeSheet(); - }, - ), + Container( + decoration: BoxDecoration( + color: AppColors.commentInput, + borderRadius: BorderRadius.circular(_inputRadius), + ), + child: TextField( + key: const Key('comment-composer-input'), + autofocus: true, + controller: _input, + focusNode: _inputFocus, + readOnly: !signedIn, + canRequestFocus: signedIn, + minLines: 1, + maxLines: 4, + maxLength: _maxCommentLength, + textAlignVertical: multiline + ? TextAlignVertical.top + : TextAlignVertical.center, + style: TextStyle( + color: AppColors.cream, + fontSize: 15, + height: multiline ? 1.4 : null, ), + cursorColor: AppColors.blue, + decoration: InputDecoration( + hintText: signedIn + ? l10n.writeComment + : l10n.commentLoginHint, + hintStyle: const TextStyle( + color: AppColors.muted, + fontSize: 14, + ), + counterText: '', + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 12, + ), + border: InputBorder.none, + enabledBorder: InputBorder.none, + focusedBorder: InputBorder.none, + ), + onTap: signedIn ? null : _authenticate, + onTapOutside: (_) { + _inputFocus.unfocus(); + _closeSheet(); + }, ), ), const SizedBox(height: 12), diff --git a/test/comment/drama_comments_sheet_test.dart b/test/comment/drama_comments_sheet_test.dart index a52cbb2..5dc2891 100644 --- a/test/comment/drama_comments_sheet_test.dart +++ b/test/comment/drama_comments_sheet_test.dart @@ -106,7 +106,8 @@ void main() { final composer = find.byKey(const Key('comment-composer-sheet')); expect(composer, findsOneWidget); - expect(tester.getSize(composer).height, closeTo(844 / 2, 0.1)); + final compactHeight = tester.getSize(composer).height; + expect(compactHeight, inInclusiveRange(100, 150)); final input = find.byKey(const Key('comment-composer-input')); expect(input, findsOneWidget); expect(tester.widget(input).focusNode?.hasFocus, isTrue); @@ -117,6 +118,8 @@ void main() { await tester.enterText(input, 'First line\nSecond line'); await tester.pump(); + expect(tester.getSize(composer).height, greaterThan(compactHeight)); + expect(tester.getSize(composer).height, lessThan(844 / 2)); final multilineField = tester.widget(input); expect(multilineField.textAlignVertical, TextAlignVertical.top); expect(multilineField.style?.height, 1.4); @@ -313,7 +316,8 @@ void main() { final composer = find.byKey(const Key('comment-composer-sheet')); final composerInput = find.byKey(const Key('comment-composer-input')); expect(composer, findsOneWidget); - expect(tester.getSize(composer).height, closeTo(844 / 2, 0.1)); + final compactHeight = tester.getSize(composer).height; + expect(compactHeight, inInclusiveRange(100, 150)); expect(tester.widget(composerInput).focusNode?.hasFocus, isTrue); final underlyingSheet = find.byKey( const Key('player-comments-sheet'), @@ -333,7 +337,7 @@ void main() { tester.view.viewInsets = const FakeViewPadding(bottom: 180); await tester.pump(); await tester.pump(const Duration(milliseconds: 200)); - expect(tester.getSize(composer).height, closeTo(844 / 2, 0.1)); + expect(tester.getSize(composer).height, closeTo(compactHeight, 0.1)); expect(tester.getBottomLeft(composer).dy, closeTo(844 - 180, 0.1)); expect( tester.getBottomLeft(composerInput).dy,