merge: 合并 K86.14 评论输入紧凑弹窗修正

This commit is contained in:
Zhou Weidong committed 2026-10-21 13:37:04 +08:00
commit 9c0c1b8982
2 files changed
+55 -62

No files matched your search

@@ -147,13 +147,6 @@ class _CommentComposerSheetState extends State<CommentComposerSheet>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screenHeight = MediaQuery.sizeOf(context).height;
final halfHeight = (screenHeight * 0.5).roundToDouble();
final maxHeight = math.max(
0.0,
screenHeight - MediaQuery.paddingOf(context).top,
);
final sheetHeight = math.min(halfHeight, maxHeight);
final keyboardHeight = _keyboardHeight(context); final keyboardHeight = _keyboardHeight(context);
final l10n = AppLocalizations.of(context)!; final l10n = AppLocalizations.of(context)!;
final signedIn = context.watch<AuthController>().isSignedIn; final signedIn = context.watch<AuthController>().isSignedIn;
@@ -167,7 +160,7 @@ class _CommentComposerSheetState extends State<CommentComposerSheet>
padding: EdgeInsets.only(bottom: keyboardHeight), padding: EdgeInsets.only(bottom: keyboardHeight),
child: SizedBox( child: SizedBox(
key: const Key('comment-composer-sheet'), key: const Key('comment-composer-sheet'),
height: sheetHeight, width: double.infinity,
child: Material( child: Material(
color: AppColors.card, color: AppColors.card,
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
@@ -177,9 +170,10 @@ class _CommentComposerSheetState extends State<CommentComposerSheet>
child: SafeArea( child: SafeArea(
top: false, top: false,
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12), padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
child: TextFieldTapRegion( child: TextFieldTapRegion(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
if (widget.replyTo != null) if (widget.replyTo != null)
@@ -197,57 +191,52 @@ class _CommentComposerSheetState extends State<CommentComposerSheet>
), ),
), ),
), ),
Expanded( Container(
child: Align( decoration: BoxDecoration(
alignment: Alignment.topCenter, color: AppColors.commentInput,
child: Container( borderRadius: BorderRadius.circular(_inputRadius),
decoration: BoxDecoration( ),
color: AppColors.commentInput, child: TextField(
borderRadius: BorderRadius.circular(_inputRadius), key: const Key('comment-composer-input'),
), autofocus: true,
child: TextField( controller: _input,
key: const Key('comment-composer-input'), focusNode: _inputFocus,
autofocus: true, readOnly: !signedIn,
controller: _input, canRequestFocus: signedIn,
focusNode: _inputFocus, minLines: 1,
readOnly: !signedIn, maxLines: 4,
canRequestFocus: signedIn, maxLength: _maxCommentLength,
minLines: 1, textAlignVertical: multiline
maxLines: 4, ? TextAlignVertical.top
maxLength: _maxCommentLength, : TextAlignVertical.center,
textAlignVertical: multiline style: TextStyle(
? TextAlignVertical.top color: AppColors.cream,
: TextAlignVertical.center, fontSize: 15,
style: TextStyle( height: multiline ? 1.4 : null,
color: AppColors.cream,
fontSize: 15,
height: multiline ? 1.4 : null,
),
cursorColor: AppColors.blue,
decoration: InputDecoration(
hintText: signedIn
? l10n.writeComment
: l10n.commentLoginHint,
hintStyle: const TextStyle(
color: AppColors.muted,
fontSize: 14,
),
counterText: '',
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
),
onTap: signedIn ? null : _authenticate,
onTapOutside: (_) {
_inputFocus.unfocus();
_closeSheet();
},
),
), ),
cursorColor: AppColors.blue,
decoration: InputDecoration(
hintText: signedIn
? l10n.writeComment
: l10n.commentLoginHint,
hintStyle: const TextStyle(
color: AppColors.muted,
fontSize: 14,
),
counterText: '',
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
),
onTap: signedIn ? null : _authenticate,
onTapOutside: (_) {
_inputFocus.unfocus();
_closeSheet();
},
), ),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
+7 -3
View File
@@ -106,7 +106,8 @@ void main() {
final composer = find.byKey(const Key('comment-composer-sheet')); final composer = find.byKey(const Key('comment-composer-sheet'));
expect(composer, findsOneWidget); expect(composer, findsOneWidget);
expect(tester.getSize(composer).height, closeTo(844 / 2, 0.1)); final compactHeight = tester.getSize(composer).height;
expect(compactHeight, inInclusiveRange(100, 150));
final input = find.byKey(const Key('comment-composer-input')); final input = find.byKey(const Key('comment-composer-input'));
expect(input, findsOneWidget); expect(input, findsOneWidget);
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue); expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
@@ -117,6 +118,8 @@ void main() {
await tester.enterText(input, 'First line\nSecond line'); await tester.enterText(input, 'First line\nSecond line');
await tester.pump(); await tester.pump();
expect(tester.getSize(composer).height, greaterThan(compactHeight));
expect(tester.getSize(composer).height, lessThan(844 / 2));
final multilineField = tester.widget<TextField>(input); final multilineField = tester.widget<TextField>(input);
expect(multilineField.textAlignVertical, TextAlignVertical.top); expect(multilineField.textAlignVertical, TextAlignVertical.top);
expect(multilineField.style?.height, 1.4); expect(multilineField.style?.height, 1.4);
@@ -313,7 +316,8 @@ void main() {
final composer = find.byKey(const Key('comment-composer-sheet')); final composer = find.byKey(const Key('comment-composer-sheet'));
final composerInput = find.byKey(const Key('comment-composer-input')); final composerInput = find.byKey(const Key('comment-composer-input'));
expect(composer, findsOneWidget); expect(composer, findsOneWidget);
expect(tester.getSize(composer).height, closeTo(844 / 2, 0.1)); final compactHeight = tester.getSize(composer).height;
expect(compactHeight, inInclusiveRange(100, 150));
expect(tester.widget<TextField>(composerInput).focusNode?.hasFocus, isTrue); expect(tester.widget<TextField>(composerInput).focusNode?.hasFocus, isTrue);
final underlyingSheet = find.byKey( final underlyingSheet = find.byKey(
const Key('player-comments-sheet'), const Key('player-comments-sheet'),
@@ -333,7 +337,7 @@ void main() {
tester.view.viewInsets = const FakeViewPadding(bottom: 180); tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
expect(tester.getSize(composer).height, closeTo(844 / 2, 0.1)); expect(tester.getSize(composer).height, closeTo(compactHeight, 0.1));
expect(tester.getBottomLeft(composer).dy, closeTo(844 - 180, 0.1)); expect(tester.getBottomLeft(composer).dy, closeTo(844 - 180, 0.1));
expect( expect(
tester.getBottomLeft(composerInput).dy, tester.getBottomLeft(composerInput).dy,