fix(player): 修正评论面板键盘态布局重叠

This commit is contained in:
Zhou Weidong committed 2026-10-21 13:00:05 +08:00
1 parent a7c0576a03
commit bc4c84a4ae
2 files changed
+95 -73

No files matched your search

+30 -16
View File
@@ -222,6 +222,7 @@ void main() {
testWidgets('should_clear_and_keep_input_focused_after_successful_post', (
tester,
) async {
addTearDown(tester.view.resetViewInsets);
final repository = FakeCommentRepository(
pages: [const CommentPage()],
publishResult: commentFixture(id: '11', content: 'Nice demo', mine: true),
@@ -230,8 +231,9 @@ void main() {
await _pumpSheet(tester, repository: repository);
final input = find.byKey(const Key('comment-input'));
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.tap(input);
await tester.pump();
await tester.pumpAndSettle();
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
await tester.enterText(input, 'Nice demo');
await tester.pump();
@@ -258,7 +260,7 @@ void main() {
expect(repository.countCalls, ['5', '5']);
});
testWidgets('should_expand_composer_only_while_input_is_focused', (
testWidgets('should_keep_composer_separate_when_keyboard_opens', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
@@ -290,6 +292,11 @@ void main() {
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);
expect(
tester.widget<TextField>(find.byKey(const Key('comment-input'))).maxLines,
1,
);
expect(tester.getSize(find.byKey(const Key('comment-input'))).height, 44);
final editableAfter = tester.state<EditableTextState>(
find.descendant(
of: find.byKey(const Key('comment-input')),
@@ -297,6 +304,16 @@ void main() {
),
);
expect(identical(editableBefore, editableAfter), isTrue);
final sheet = find.byKey(const Key('player-comments-sheet'));
final list = find.byKey(const Key('comment-list'));
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
expect(sheet, findsOneWidget);
expect(list, findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
final field = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
);
@@ -310,6 +327,10 @@ void main() {
isNull,
);
expect(tester.getSize(find.byKey(const Key('comment-post'))).height, 32);
final listRect = tester.getRect(list);
final inputRect = tester.getRect(find.byKey(const Key('comment-input')));
expect(listRect.overlaps(inputRect), isFalse);
expect(listRect.bottom, lessThanOrEqualTo(inputRect.top));
expect(find.byIcon(Icons.image_outlined), findsNothing);
expect(find.byIcon(Icons.emoji_emotions_outlined), findsNothing);
expect(find.byIcon(Icons.alternate_email_rounded), findsNothing);
@@ -323,16 +344,6 @@ 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: 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')),
@@ -340,8 +351,7 @@ void main() {
),
);
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(sheet).dy, closeTo(844 - 180, 0.1));
expect(
tester.widget<ListView>(list).padding?.resolve(TextDirection.ltr).bottom,
greaterThanOrEqualTo(180 + 44),
@@ -363,6 +373,12 @@ void main() {
expect(list, findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
expect(find.byKey(const Key('comment-composer')), findsOneWidget);
final collapsedField = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
);
expect(collapsedField.maxLines, 1);
expect(tester.getSize(find.byKey(const Key('comment-input'))).height, 44);
expect(tester.getSize(sheet).height, lessThan(520));
final editableAfterKeyboard = tester.state<EditableTextState>(
find.descendant(
of: find.byKey(const Key('comment-input')),
@@ -370,8 +386,6 @@ void main() {
),
);
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')))