fix(app): an empty Cupertino composer is as tall as its wrapped placeholder
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -687,18 +688,53 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The lines the composer placeholder needs at [width] (the field's
|
||||
/// default 7px side padding excluded), capped at 3.
|
||||
int _placeholderLines(BuildContext context, double width) {
|
||||
if (!width.isFinite) return 1;
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(
|
||||
text: chatComposerPlaceholder,
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
),
|
||||
textDirection: Directionality.of(context),
|
||||
textScaler: MediaQuery.textScalerOf(context),
|
||||
maxLines: 3,
|
||||
)..layout(maxWidth: math.max(0, width - 14));
|
||||
final lines = painter.computeLineMetrics().length;
|
||||
painter.dispose();
|
||||
return lines.clamp(1, 3);
|
||||
}
|
||||
|
||||
Widget _field(bool cupertino) {
|
||||
if (cupertino) {
|
||||
return CupertinoTextField(
|
||||
key: const Key('chat-composer-field'),
|
||||
controller: _text,
|
||||
focusNode: _focus,
|
||||
placeholder: chatComposerPlaceholder,
|
||||
minLines: 1,
|
||||
maxLines: 6,
|
||||
keyboardType: TextInputType.multiline,
|
||||
textInputAction: TextInputAction.newline,
|
||||
onChanged: _onDraftEdited,
|
||||
// CupertinoTextField lays its placeholder out with up to maxLines lines
|
||||
// but sizes an empty field by minLines, so a wrapped placeholder was
|
||||
// clipped on a narrow pane. While empty the field is exactly as tall as
|
||||
// its placeholder (at most 3 lines, then ellipsised); typing restores
|
||||
// the normal 1-6 lines.
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final empty = _text.text.isEmpty;
|
||||
final lines = empty
|
||||
? _placeholderLines(context, constraints.maxWidth)
|
||||
: 1;
|
||||
return CupertinoTextField(
|
||||
key: const Key('chat-composer-field'),
|
||||
controller: _text,
|
||||
focusNode: _focus,
|
||||
placeholder: chatComposerPlaceholder,
|
||||
placeholderStyle: const TextStyle(
|
||||
color: CupertinoColors.placeholderText,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
minLines: lines,
|
||||
maxLines: empty ? lines : 6,
|
||||
keyboardType: TextInputType.multiline,
|
||||
textInputAction: TextInputAction.newline,
|
||||
onChanged: _onDraftEdited,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
return TextField(
|
||||
|
||||
Reference in New Issue
Block a user