fix(player): 聚焦时保留评论列表并稳定焦点

This commit is contained in:
Zhou Weidong committed 2026-10-21 12:53:46 +08:00
1 parent de99c09454
commit ad69ef7f54
2 files changed
+141 -115

No files matched your search

+42 -11
View File
@@ -247,7 +247,8 @@ void main() {
expect(tester.widget<TextField>(input).controller?.text, isEmpty);
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
expect(tester.widget<TextField>(input).maxLines, 4);
expect(find.byKey(const Key('comment-list')), findsNothing);
expect(find.byKey(const Key('comment-list')), findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
expect(
tester
.widget<TextButton>(find.byKey(const Key('comment-post')))
@@ -285,8 +286,8 @@ void main() {
await tester.tap(find.byKey(const Key('comment-input')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('comment-list')), findsNothing);
expect(find.byKey(const Key('comment-count-label')), findsNothing);
expect(find.byKey(const Key('comment-list')), findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
expect(find.byKey(const Key('comment-composer')), findsOneWidget);
expect(find.byKey(const Key('comment-input-surface')), findsOneWidget);
final editableAfter = tester.state<EditableTextState>(
@@ -309,7 +310,6 @@ void main() {
isNull,
);
expect(tester.getSize(find.byKey(const Key('comment-post'))).height, 32);
expect(find.byType(IconButton), findsNothing);
expect(find.byIcon(Icons.image_outlined), findsNothing);
expect(find.byIcon(Icons.emoji_emotions_outlined), findsNothing);
expect(find.byIcon(Icons.alternate_email_rounded), findsNothing);
@@ -323,24 +323,55 @@ void main() {
isNotNull,
);
final sheet = find.byKey(const Key('player-comments-sheet'));
final list = find.byKey(const Key('comment-list'));
final sheetTop = tester.getTopLeft(sheet).dy;
final listTop = tester.getTopLeft(list).dy;
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.pump();
await tester.pump(const Duration(milliseconds: 160));
expect(find.byKey(const Key('player-comments-sheet')), findsOneWidget);
expect(find.byKey(const Key('comment-list')), findsNothing);
await tester.pump(const Duration(milliseconds: 200));
expect(sheet, findsOneWidget);
expect(list, findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
final editableDuringKeyboard = tester.state<EditableTextState>(
find.descendant(
of: find.byKey(const Key('comment-input')),
matching: find.byType(EditableText),
),
);
expect(identical(editableAfter, editableDuringKeyboard), isTrue);
expect(tester.getTopLeft(sheet).dy, closeTo(sheetTop, 0.1));
expect(tester.getTopLeft(list).dy, closeTo(listTop, 0.1));
expect(
tester.getBottomLeft(find.byKey(const Key('player-comments-sheet'))).dy,
closeTo(844 - 180, 0.1),
tester.widget<ListView>(list).padding?.resolve(TextDirection.ltr).bottom,
greaterThanOrEqualTo(180 + 44),
);
expect(
tester.getBottomLeft(find.byKey(const Key('comment-input'))).dy,
lessThanOrEqualTo(844 - 180),
);
expect(
tester
.widget<TextField>(find.byKey(const Key('comment-input')))
.focusNode
?.hasFocus,
isTrue,
);
tester.view.viewInsets = const FakeViewPadding();
await tester.pumpAndSettle();
expect(find.byKey(const Key('comment-list')), findsOneWidget);
expect(list, findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
expect(find.byKey(const Key('comment-composer')), findsOneWidget);
final editableAfterKeyboard = tester.state<EditableTextState>(
find.descendant(
of: find.byKey(const Key('comment-input')),
matching: find.byType(EditableText),
),
);
expect(identical(editableAfter, editableAfterKeyboard), isTrue);
expect(tester.getTopLeft(sheet).dy, closeTo(sheetTop, 0.1));
expect(tester.getTopLeft(list).dy, closeTo(listTop, 0.1));
expect(
tester
.widget<TextField>(find.byKey(const Key('comment-input')))
@@ -353,7 +384,7 @@ void main() {
.widget<TextField>(find.byKey(const Key('comment-input')))
.focusNode
?.hasFocus,
isFalse,
isTrue,
);
});