fix(player): 评论面板保持高度并两段式收起

This commit is contained in:
Zhou Weidong committed 2026-10-21 13:04:29 +08:00
1 parent 9876772d06
commit d081cff3e4
3 files changed
+128 -51

No files matched your search

+2
View File
@@ -810,6 +810,8 @@ class PlayerLogic extends ChangeNotifier {
isScrollControlled: true,
backgroundColor: Colors.transparent,
showDragHandle: false,
isDismissible: false,
enableDrag: false,
builder: (_) => DramaCommentsSheet(drama: drama),
);
} finally {
@@ -178,6 +178,14 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
).showSnackBar(SnackBar(content: Text(message)));
}
void _handleDismissLayerTap() {
if (_inputFocus.hasFocus || _keyboardHeight(context) > 0) {
_inputFocus.unfocus();
return;
}
Navigator.pop(context);
}
@override
Widget build(BuildContext context) {
final screenLimit = MediaQuery.sizeOf(context).height - 24;
@@ -194,61 +202,80 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
availableHeight,
);
_measureSheetWithoutKeyboard(keyboardHeight);
return AnimatedPadding(
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
padding: EdgeInsets.only(bottom: keyboardHeight),
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: inputFocused ? _inputFocus.unfocus : null,
child: SizedBox(
key: _sheetMeasureKey,
child: Container(
key: const Key('player-comments-sheet'),
decoration: const BoxDecoration(
color: AppColors.card,
borderRadius: BorderRadius.vertical(
top: Radius.circular(_sheetRadius),
),
),
child: SafeArea(
top: false,
child: ListenableBuilder(
listenable: _controller,
builder: (context, _) {
final minHeight = _controller.comments.isEmpty
? (_minSheetHeight < maxHeight
? _minSheetHeight
: maxHeight)
: 0.0;
return AnimatedSize(
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
alignment: Alignment.bottomCenter,
child: ConstrainedBox(
key: const Key('comment-sheet-constraints'),
constraints: keyboardOpen
? BoxConstraints.tightFor(height: keyboardPanelHeight)
: BoxConstraints(
minHeight: minHeight,
maxHeight: maxHeight,
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: _content(
context,
expanded: expanded,
keyboardHeight: keyboardHeight,
),
),
return Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
child: GestureDetector(
key: const Key('player-comments-dismiss-layer'),
behavior: HitTestBehavior.opaque,
onTap: _handleDismissLayerTap,
),
),
Align(
alignment: Alignment.bottomCenter,
child: AnimatedPadding(
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
padding: EdgeInsets.only(bottom: keyboardHeight),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {},
child: SizedBox(
key: _sheetMeasureKey,
child: Container(
key: const Key('player-comments-sheet'),
decoration: const BoxDecoration(
color: AppColors.card,
borderRadius: BorderRadius.vertical(
top: Radius.circular(_sheetRadius),
),
);
},
),
child: SafeArea(
top: false,
child: ListenableBuilder(
listenable: _controller,
builder: (context, _) {
final minHeight = _controller.comments.isEmpty
? (_minSheetHeight < maxHeight
? _minSheetHeight
: maxHeight)
: 0.0;
return AnimatedSize(
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
alignment: Alignment.bottomCenter,
child: ConstrainedBox(
key: const Key('comment-sheet-constraints'),
constraints: keyboardOpen
? BoxConstraints.tightFor(
height: keyboardPanelHeight,
)
: BoxConstraints(
minHeight: minHeight,
maxHeight: maxHeight,
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: _content(
context,
expanded: expanded,
keyboardHeight: keyboardHeight,
),
),
),
);
},
),
),
),
),
),
),
),
),
],
);
}
@@ -509,7 +536,6 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
focused: focused,
),
onTap: signedIn ? null : _authenticateForComment,
onTapOutside: (_) => _inputFocus.unfocus(),
onSubmitted: focused ? null : (_) => _post(),
),
),