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:
@@ -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));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user