703 lines
24 KiB
Dart
703 lines
24 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'dart:async';
|
|
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../core/data/models/comment.dart';
|
|
import '../../../core/data/models/drama.dart';
|
|
import '../../../core/data/repositories/comment_repository.dart';
|
|
import '../../../core/data/repositories/interaction_repository.dart';
|
|
import '../../../core/data/services/comment_controller.dart';
|
|
import '../../../core/data/services/auth_controller.dart';
|
|
import '../../../core/formatting/error_text.dart';
|
|
import '../../../core/platform/haptics.dart';
|
|
import '../../../core/platform/keyboard_inset.dart';
|
|
import '../../../core/theme/app_colors.dart';
|
|
import '../../../core/widgets/auth_gate.dart';
|
|
import '../../../core/widgets/empty_state.dart';
|
|
import '../../../l10n/app_localizations.dart';
|
|
import 'comment_tile.dart';
|
|
|
|
const double _minSheetHeight = 280;
|
|
const double _maxSheetHeight = 520;
|
|
const int _maxCommentLength = 300;
|
|
const double _composerRadius = 22;
|
|
const double _composerHeight = 44;
|
|
const double _sendButtonSize = 38;
|
|
const double _sheetRadius = 20;
|
|
const double _headerHeight = 44;
|
|
const double _replyIndent = 52;
|
|
const double _composerTopGap = 8;
|
|
const double _replyBannerHeight = 46;
|
|
const double _expandedInputRadius = 12;
|
|
const double _postButtonHeight = 32;
|
|
const double _expandedComposerReserve = 113;
|
|
|
|
/// 服务端评论底部弹窗:匿名列表、游标翻页、回复与登录发布。
|
|
class DramaCommentsSheet extends StatefulWidget {
|
|
const DramaCommentsSheet({super.key, required this.drama});
|
|
|
|
final Drama drama;
|
|
|
|
@override
|
|
State<DramaCommentsSheet> createState() => _DramaCommentsSheetState();
|
|
}
|
|
|
|
class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
|
final _input = TextEditingController();
|
|
final _inputFocus = FocusNode();
|
|
final _keyboardInset = KeyboardInsetNotifier.instance;
|
|
final _sheetMeasureKey = GlobalKey();
|
|
late final CommentRepository _comments;
|
|
late final CommentController _controller;
|
|
DramaComment? _replyTo;
|
|
int? _serverCount;
|
|
int _countRequest = 0;
|
|
double? _sheetHeightWithoutKeyboard;
|
|
bool _sheetMeasureScheduled = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_inputFocus.addListener(_onFocusChanged);
|
|
_input.addListener(_onInputChanged);
|
|
_keyboardInset.addListener(_onKeyboardInsetChanged);
|
|
unawaited(_keyboardInset.start());
|
|
_comments = context.read<CommentRepository>();
|
|
_controller = CommentController(
|
|
comments: _comments,
|
|
interactions: context.read<InteractionRepository>(),
|
|
dramaId: widget.drama.id,
|
|
);
|
|
unawaited(_controller.load());
|
|
unawaited(_refreshCount());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_keyboardInset.removeListener(_onKeyboardInsetChanged);
|
|
_inputFocus.removeListener(_onFocusChanged);
|
|
_input.removeListener(_onInputChanged);
|
|
_controller.dispose();
|
|
_input.dispose();
|
|
_inputFocus.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _onFocusChanged() {
|
|
if (mounted) setState(() {});
|
|
}
|
|
|
|
void _onInputChanged() {
|
|
if (mounted) setState(() {});
|
|
}
|
|
|
|
void _onKeyboardInsetChanged() {
|
|
if (!mounted) return;
|
|
setState(() {});
|
|
}
|
|
|
|
double _keyboardHeight(BuildContext context) => math.max(
|
|
MediaQuery.viewInsetsOf(context).bottom,
|
|
_keyboardInset.value / MediaQuery.devicePixelRatioOf(context),
|
|
);
|
|
|
|
void _measureSheetWithoutKeyboard(double keyboardHeight) {
|
|
if (keyboardHeight > 0 || _sheetMeasureScheduled) return;
|
|
_sheetMeasureScheduled = true;
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_sheetMeasureScheduled = false;
|
|
if (!mounted) return;
|
|
if (_keyboardHeight(context) > 0) return;
|
|
final box = _sheetMeasureKey.currentContext?.findRenderObject();
|
|
if (box is! RenderBox || !box.hasSize) return;
|
|
final height = box.size.height;
|
|
if (!height.isFinite ||
|
|
(_sheetHeightWithoutKeyboard != null &&
|
|
(height - _sheetHeightWithoutKeyboard!).abs() < 0.5)) {
|
|
return;
|
|
}
|
|
setState(() => _sheetHeightWithoutKeyboard = height);
|
|
});
|
|
}
|
|
|
|
Future<void> _post() async {
|
|
if (_controller.submitting) return;
|
|
if (!await ensureSignedIn(context) || !mounted) return;
|
|
if (_input.text.trim().isEmpty) return;
|
|
unawaited(context.read<Haptics>().lightImpact());
|
|
final result = await _controller.publish(_input.text, replyTo: _replyTo);
|
|
if (!mounted) return;
|
|
if (result.isSuccess) {
|
|
_input.clear();
|
|
setState(() => _replyTo = null);
|
|
_inputFocus.requestFocus();
|
|
await _refreshCount();
|
|
return;
|
|
}
|
|
_showMessage(
|
|
result.errorMessage ?? AppLocalizations.of(context)!.commentPostFailed,
|
|
);
|
|
}
|
|
|
|
void _beginReply(DramaComment comment) {
|
|
setState(() => _replyTo = comment);
|
|
_inputFocus.requestFocus();
|
|
}
|
|
|
|
void _cancelReply() {
|
|
if (_replyTo == null) return;
|
|
setState(() => _replyTo = null);
|
|
}
|
|
|
|
Future<void> _authenticateForComment() async {
|
|
_inputFocus.unfocus();
|
|
await ensureSignedIn(context);
|
|
if (!mounted || !context.read<AuthController>().isSignedIn) return;
|
|
_inputFocus.requestFocus();
|
|
}
|
|
|
|
Future<void> _refreshCount() async {
|
|
final request = ++_countRequest;
|
|
try {
|
|
final count = await _comments.count(widget.drama.id);
|
|
if (!mounted || request != _countRequest) return;
|
|
setState(() => _serverCount = count);
|
|
} catch (_) {
|
|
if (!mounted || request != _countRequest) return;
|
|
setState(() => _serverCount = null);
|
|
}
|
|
}
|
|
|
|
void _showMessage(String message) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).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;
|
|
final maxHeight = screenLimit < _maxSheetHeight
|
|
? screenLimit
|
|
: _maxSheetHeight;
|
|
final inputFocused = _inputFocus.hasFocus;
|
|
final keyboardHeight = _keyboardHeight(context);
|
|
final keyboardOpen = keyboardHeight > 0;
|
|
final expanded = inputFocused && keyboardOpen;
|
|
final availableHeight = math.max(0.0, screenLimit - keyboardHeight);
|
|
final keyboardPanelHeight = math.min(
|
|
_sheetHeightWithoutKeyboard ?? maxHeight,
|
|
availableHeight,
|
|
);
|
|
_measureSheetWithoutKeyboard(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,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _content(
|
|
BuildContext context, {
|
|
required bool expanded,
|
|
required double keyboardHeight,
|
|
}) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final count = _serverCount ?? _controller.exactCount;
|
|
final composerReserve = expanded
|
|
? _expandedComposerReserve
|
|
: _composerHeight + _composerTopGap;
|
|
return Column(
|
|
key: const Key('comment-sheet-content'),
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SizedBox(
|
|
height: _headerHeight,
|
|
width: double.infinity,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Text(
|
|
count == null ? l10n.comments : l10n.commentsWithCount(count),
|
|
key: const Key('comment-count-label'),
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
color: AppColors.onSurface,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
Positioned(
|
|
left: 0,
|
|
child: SizedBox.square(
|
|
dimension: 44,
|
|
child: IconButton(
|
|
key: const Key('player-comments-close'),
|
|
tooltip: l10n.close,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () => Navigator.pop(context),
|
|
icon: const Icon(
|
|
Icons.keyboard_arrow_down_rounded,
|
|
size: 24,
|
|
color: AppColors.cream,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Flexible(
|
|
fit: FlexFit.loose,
|
|
child: _list(
|
|
l10n,
|
|
composerReserve: composerReserve,
|
|
keyboardHeight: keyboardHeight,
|
|
),
|
|
),
|
|
if (_replyTo != null) _replyBanner(l10n, _replyTo!),
|
|
Padding(
|
|
key: const Key('comment-composer-area'),
|
|
padding: EdgeInsets.only(
|
|
top: expanded ? 12 : _composerTopGap,
|
|
bottom: expanded ? 12 : 0,
|
|
),
|
|
child: _composer(l10n, focused: expanded),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _list(
|
|
AppLocalizations l10n, {
|
|
required double composerReserve,
|
|
required double keyboardHeight,
|
|
}) {
|
|
if (_controller.loading && _controller.comments.isEmpty) {
|
|
return const Padding(
|
|
padding: EdgeInsets.only(top: 4),
|
|
child: Center(
|
|
child: CircularProgressIndicator(key: Key('comment-list-loading')),
|
|
),
|
|
);
|
|
}
|
|
if (_controller.error != null && _controller.comments.isEmpty) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: EmptyState(
|
|
key: const Key('comment-list-error'),
|
|
icon: Icons.cloud_off_rounded,
|
|
title: errorText(l10n, _controller.error, l10n.commentsLoadFailed),
|
|
actionLabel: l10n.retry,
|
|
actionKey: const Key('comment-list-retry'),
|
|
onAction: _controller.load,
|
|
compact: true,
|
|
),
|
|
);
|
|
}
|
|
if (_controller.comments.isEmpty) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: EmptyState(
|
|
key: const Key('comment-list-empty'),
|
|
icon: Icons.chat_bubble_outline_rounded,
|
|
title: l10n.noComments,
|
|
compact: true,
|
|
),
|
|
);
|
|
}
|
|
return ListView.builder(
|
|
key: const Key('comment-list'),
|
|
shrinkWrap: true,
|
|
padding: EdgeInsets.only(
|
|
top: 4,
|
|
bottom: composerReserve + keyboardHeight,
|
|
),
|
|
itemCount: _controller.comments.length + 1,
|
|
itemBuilder: (context, index) {
|
|
if (index == _controller.comments.length) return _footer(l10n);
|
|
return _CommentThread(
|
|
comment: _controller.comments[index],
|
|
controller: _controller,
|
|
handlers: CommentInteractionHandlers(onReply: _beginReply),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _footer(AppLocalizations l10n) {
|
|
if (_controller.loadingMore) {
|
|
return const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 12),
|
|
child: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
if (_controller.hasMore) {
|
|
return TextButton(
|
|
key: const Key('comment-list-load-more'),
|
|
onPressed: _controller.loadMore,
|
|
child: Text(l10n.loadMore),
|
|
);
|
|
}
|
|
return const SizedBox(height: 8);
|
|
}
|
|
|
|
Widget _replyBanner(AppLocalizations l10n, DramaComment replyTo) => SizedBox(
|
|
height: _replyBannerHeight,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(bottom: 6),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
l10n.replyingTo(
|
|
replyTo.nickname.isEmpty
|
|
? l10n.anonymousUser
|
|
: replyTo.nickname,
|
|
),
|
|
style: const TextStyle(color: AppColors.muted, fontSize: 12),
|
|
),
|
|
),
|
|
IconButton(
|
|
key: const Key('comment-cancel-reply'),
|
|
tooltip: l10n.cancelReply,
|
|
onPressed: _cancelReply,
|
|
visualDensity: VisualDensity.compact,
|
|
icon: const Icon(Icons.close_rounded, size: 18),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
InputDecoration _composerDecoration(String hint, {required bool focused}) {
|
|
final radius = BorderRadius.circular(
|
|
focused ? _expandedInputRadius : _composerRadius,
|
|
);
|
|
final clear = OutlineInputBorder(
|
|
borderRadius: radius,
|
|
borderSide: BorderSide.none,
|
|
);
|
|
return InputDecoration(
|
|
hintText: hint,
|
|
hintStyle: const TextStyle(color: AppColors.muted, fontSize: 14),
|
|
counterText: '',
|
|
contentPadding: EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: focused ? 12 : 0,
|
|
),
|
|
isDense: true,
|
|
border: clear,
|
|
enabledBorder: clear,
|
|
focusedBorder: clear,
|
|
);
|
|
}
|
|
|
|
Widget _composer(AppLocalizations l10n, {required bool focused}) {
|
|
final signedIn = context.watch<AuthController>().isSignedIn;
|
|
final hasContent = _input.text.trim().isNotEmpty;
|
|
final canPost = signedIn && hasContent && !_controller.submitting;
|
|
return Container(
|
|
key: const Key('comment-composer'),
|
|
padding: focused ? EdgeInsets.zero : const EdgeInsets.only(right: 3),
|
|
decoration: BoxDecoration(
|
|
color: focused ? Colors.transparent : AppColors.commentInput,
|
|
borderRadius: BorderRadius.circular(focused ? 0 : _composerRadius),
|
|
),
|
|
child: TextFieldTapRegion(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
AnimatedContainer(
|
|
key: const Key('comment-input-surface'),
|
|
duration: const Duration(milliseconds: 150),
|
|
curve: Curves.easeOut,
|
|
decoration: BoxDecoration(
|
|
color: focused ? AppColors.commentInput : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(
|
|
focused ? _expandedInputRadius : _composerRadius,
|
|
),
|
|
),
|
|
child: SizedBox(
|
|
height: focused ? null : _composerHeight,
|
|
child: Row(
|
|
crossAxisAlignment: focused
|
|
? CrossAxisAlignment.start
|
|
: CrossAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: focused ? null : _composerHeight,
|
|
child: TextField(
|
|
key: const Key('comment-input'),
|
|
controller: _input,
|
|
focusNode: _inputFocus,
|
|
readOnly: !signedIn,
|
|
canRequestFocus: signedIn,
|
|
minLines: 1,
|
|
maxLines: focused ? 4 : 1,
|
|
maxLength: _maxCommentLength,
|
|
textAlignVertical: focused
|
|
? TextAlignVertical.top
|
|
: TextAlignVertical.center,
|
|
style: TextStyle(
|
|
color: AppColors.cream,
|
|
fontSize: focused ? 15 : 14,
|
|
),
|
|
cursorColor: AppColors.blue,
|
|
decoration: _composerDecoration(
|
|
signedIn
|
|
? l10n.writeComment
|
|
: l10n.commentLoginHint,
|
|
focused: focused,
|
|
),
|
|
onTap: signedIn ? null : _authenticateForComment,
|
|
onSubmitted: focused ? null : (_) => _post(),
|
|
),
|
|
),
|
|
),
|
|
if (!focused)
|
|
SizedBox.square(
|
|
dimension: _sendButtonSize,
|
|
child: IconButton.filled(
|
|
key: const Key('comment-post'),
|
|
tooltip: l10n.postComment,
|
|
padding: EdgeInsets.zero,
|
|
iconSize: 18,
|
|
onPressed: _controller.submitting ? null : _post,
|
|
icon: _controller.submitting
|
|
? const SizedBox.square(
|
|
dimension: 16,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
),
|
|
)
|
|
: const Icon(Icons.send_rounded),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
if (focused) ...[
|
|
const SizedBox(height: 12),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: SizedBox(
|
|
height: _postButtonHeight,
|
|
child: TextButton(
|
|
key: const Key('comment-post'),
|
|
onPressed: canPost ? _post : null,
|
|
style: TextButton.styleFrom(
|
|
minimumSize: const Size(0, _postButtonHeight),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
backgroundColor: hasContent
|
|
? AppColors.blue.withValues(alpha: 0.12)
|
|
: AppColors.raised,
|
|
foregroundColor: AppColors.blue,
|
|
disabledForegroundColor: AppColors.muted,
|
|
disabledBackgroundColor: AppColors.raised,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
child: Text(
|
|
l10n.postComment,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _CommentThread extends StatelessWidget {
|
|
const _CommentThread({
|
|
required this.comment,
|
|
required this.controller,
|
|
required this.handlers,
|
|
});
|
|
|
|
final DramaComment comment;
|
|
final CommentController controller;
|
|
final CommentInteractionHandlers handlers;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final replies = controller.repliesFor(comment.id);
|
|
final expanded = controller.repliesExpanded(comment.id);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
CommentTile(comment: comment, handlers: handlers),
|
|
if (comment.replyCount > 0 || replies.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: _replyIndent, bottom: 4),
|
|
child: TextButton(
|
|
key: Key('comment-replies-${comment.id}'),
|
|
onPressed: () => _toggleReplies(context),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: AppColors.muted,
|
|
padding: EdgeInsets.zero,
|
|
minimumSize: const Size(0, 24),
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(width: 16, height: 1, color: AppColors.border),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
expanded
|
|
? AppLocalizations.of(context)!.hideReplies
|
|
: AppLocalizations.of(
|
|
context,
|
|
)!.viewReplies(comment.replyCount),
|
|
style: const TextStyle(
|
|
color: AppColors.muted,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
Icon(
|
|
expanded
|
|
? Icons.keyboard_arrow_up_rounded
|
|
: Icons.keyboard_arrow_down_rounded,
|
|
size: 14,
|
|
color: AppColors.muted,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
if (expanded)
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: _replyIndent),
|
|
child: Column(
|
|
children: [
|
|
if (controller.repliesLoading(comment.id))
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
for (final reply in replies)
|
|
CommentTile(
|
|
comment: reply,
|
|
handlers: handlers,
|
|
isReply: true,
|
|
),
|
|
if (controller.repliesHasMore(comment.id))
|
|
TextButton(
|
|
onPressed: () => controller.loadMoreReplies(comment.id),
|
|
child: Text(AppLocalizations.of(context)!.loadMore),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<void> _toggleReplies(BuildContext context) async {
|
|
if (controller.repliesExpanded(comment.id)) {
|
|
controller.hideReplies(comment.id);
|
|
return;
|
|
}
|
|
await controller.loadReplies(comment.id);
|
|
}
|
|
}
|