From cb58f649c138c650715cccb19fdcf1fbe093fd56 Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Wed, 21 Oct 2026 14:10:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(player):=20=E6=94=B6=E8=B5=B7=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E4=B8=8D=E5=85=B3=E9=97=AD=E8=AF=84=E8=AE=BA=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/comment_composer_sheet.dart | 40 +------------------ test/comment/drama_comments_sheet_test.dart | 36 ++++++++++++++++- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/lib/pages/player/widgets/comment_composer_sheet.dart b/lib/pages/player/widgets/comment_composer_sheet.dart index 1636240..104cf5c 100644 --- a/lib/pages/player/widgets/comment_composer_sheet.dart +++ b/lib/pages/player/widgets/comment_composer_sheet.dart @@ -35,21 +35,16 @@ class CommentComposerSheet extends StatefulWidget { State createState() => _CommentComposerSheetState(); } -class _CommentComposerSheetState extends State - with WidgetsBindingObserver { +class _CommentComposerSheetState extends State { final _input = TextEditingController(); final _inputFocus = FocusNode(); final _keyboardInset = KeyboardInsetNotifier.instance; - bool _keyboardWasVisible = false; - bool _hadFocus = false; bool _closing = false; @override void initState() { super.initState(); - WidgetsBinding.instance.addObserver(this); _input.addListener(_onInputChanged); - _inputFocus.addListener(_onFocusChanged); _keyboardInset.addListener(_onKeyboardInsetChanged); widget.controller.addListener(_onControllerChanged); unawaited(_keyboardInset.start()); @@ -57,9 +52,7 @@ class _CommentComposerSheetState extends State @override void dispose() { - WidgetsBinding.instance.removeObserver(this); _input.removeListener(_onInputChanged); - _inputFocus.removeListener(_onFocusChanged); _keyboardInset.removeListener(_onKeyboardInsetChanged); widget.controller.removeListener(_onControllerChanged); _input.dispose(); @@ -75,36 +68,9 @@ class _CommentComposerSheetState extends State if (mounted) setState(() {}); } - void _onFocusChanged() { - if (!mounted) return; - final hasFocus = _inputFocus.hasFocus; - if (_hadFocus && !hasFocus) { - _closeSheet(); - } - _hadFocus = hasFocus; - setState(() {}); - } - void _onKeyboardInsetChanged() { if (!mounted) return; setState(() {}); - _syncKeyboardVisibility(_keyboardHeight(context)); - } - - @override - void didChangeMetrics() { - WidgetsBinding.instance.addPostFrameCallback((_) { - if (!mounted) return; - _syncKeyboardVisibility(_keyboardHeight(context)); - }); - } - - void _syncKeyboardVisibility(double keyboardHeight) { - if (keyboardHeight > 0) { - _keyboardWasVisible = true; - return; - } - if (_keyboardWasVisible) _closeSheet(); } double _keyboardHeight(BuildContext context) => math.max( @@ -254,10 +220,6 @@ class _CommentComposerSheetState extends State 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 e1dc5b6..b6a715a 100644 --- a/test/comment/drama_comments_sheet_test.dart +++ b/test/comment/drama_comments_sheet_test.dart @@ -387,7 +387,8 @@ void main() { tester.view.viewInsets = const FakeViewPadding(); await tester.pumpAndSettle(); - expect(composer, findsNothing); + expect(composer, findsOneWidget); + expect(tester.getBottomLeft(composer).dy, closeTo(844, 0.1)); expect(commentsSheet, findsOneWidget); expect(list, findsOneWidget); expect(placeholder, findsOneWidget); @@ -395,6 +396,35 @@ void main() { expect(tester.getSize(commentsSheet).height, closeTo(sheetHeight, 0.1)); }); + testWidgets('should_keep_composer_open_after_input_loses_focus', ( + tester, + ) async { + final repository = FakeCommentRepository( + pages: [ + CommentPage( + comments: [commentFixture(id: '10', content: 'A comment')], + ), + ], + ); + + await _pumpSheet(tester, repository: repository); + await tester.tap(find.byKey(const Key('comment-input-placeholder'))); + await tester.pumpAndSettle(); + + final composer = find.byKey(const Key('comment-composer-sheet')); + final input = find.byKey(const Key('comment-composer-input')); + expect(composer, findsOneWidget); + + tester.widget(input).focusNode?.unfocus(); + await tester.pumpAndSettle(); + expect(composer, findsOneWidget); + + await tester.tap(input); + await tester.pump(); + expect(composer, findsOneWidget); + expect(tester.widget(input).focusNode?.hasFocus, isTrue); + }); + testWidgets('should_close_composer_before_comment_panel_from_outside', ( tester, ) async { @@ -430,6 +460,10 @@ void main() { final sheetRect = tester.getRect(sheet); final composerRect = tester.getRect(composer); + await tester.tap(find.byKey(const Key('comment-composer-input'))); + await tester.pump(); + expect(composer, findsOneWidget); + await tester.tapAt( Offset(sheetRect.center.dx, (sheetRect.top + composerRect.top) / 2), );