Chat composer: grow to 12 lines, at most ~40% of the visible height

The message field grows up to 12 lines (was 6) before it scrolls, capped at
about 40% of the visible height with the keyboard excluded, so the
conversation stays in view on a phone.
This commit is contained in:
2026-11-03 10:37:39 +00:00
parent 6413fc5a90
commit 73646a038d
2 changed files with 64 additions and 3 deletions
@@ -0,0 +1,43 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'chat_composer_bar_fixtures.dart';
/// The composer grows to 12 lines before it scrolls, but never past about
/// 40% of the visible height (the keyboard excluded).
void main() {
int? maxLinesOf(WidgetTester tester, bool cupertino) {
final field = find.byKey(const Key('chat-composer-field'));
return cupertino
? tester.widget<CupertinoTextField>(field).maxLines
: tester.widget<TextField>(field).maxLines;
}
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: a tall window allows 12 lines; a phone with its '
'keyboard open fewer', (tester) async {
final gateway = ComposerBarGateway()..page = fixtureTurn();
addTearDown(gateway.close);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
tester.view.physicalSize = const Size(900, 1000);
await tester.pumpWidget(composerThread(gateway, cupertino: cupertino));
await tester.pump();
// A non-empty field (the Cupertino placeholder sizing only applies
// while empty).
await tester.enterText(find.byKey(const Key('chat-composer-field')), 'x');
await tester.pump();
expect(maxLinesOf(tester, cupertino), 12);
tester.view.physicalSize = const Size(390, 844);
tester.view.viewInsets = const FakeViewPadding(bottom: 340);
await tester.pump();
final phone = maxLinesOf(tester, cupertino)!;
expect(phone, lessThan(12));
expect(phone, greaterThan(6));
});
}
}