merge: 合并 K40-B 评论入口登录闸

This commit is contained in:
Zhou Weidong committed 2026-10-20 16:12:34 +08:00
commit 230f16a44a
3 files changed
+59 -2

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
// Author: fruit.com.cn
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../core/data/models/drama.dart';
import '../../core/data/services/auth_controller.dart';
import '../../core/widgets/auth_gate.dart';
/// 评论入口统一登录闸:登录成功且页面仍存在时再打开评论面板。
Future<void> openCommentsWithAuth(
BuildContext context,
Drama drama, {
required Future<void> Function(BuildContext context, Drama drama) show,
}) async {
final auth = context.read<AuthController>();
if (auth.isSignedIn) {
await show(context, drama);
return;
}
await ensureSignedIn(context);
if (!context.mounted || !auth.isSignedIn) return;
await show(context, drama);
}
+7 -2
View File
@@ -22,6 +22,7 @@ import '../../core/widgets/auth_gate.dart';
import '../../core/widgets/download_action.dart';
import '../../core/widgets/remote_image.dart';
import '../../l10n/app_localizations.dart';
import 'comments_auth.dart';
import 'player_binding.dart';
import 'player_logic.dart';
import 'widgets/home_feed_header.dart';
@@ -454,7 +455,9 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
);
}
},
onComments: () => logic.showComments(context, drama),
onComments: () => unawaited(
openCommentsWithAuth(context, drama, show: logic.showComments),
),
onShare: () => logic.shareDrama(context, drama),
onDetail: () => unawaited(logic.openDetail(context)),
onOpenFullPlayer: () async {
@@ -498,7 +501,9 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
onDetail: () => unawaited(logic.openDetail(context)),
onSpeed: () => unawaited(_openSpeedSheet(context)),
onEpisodes: () => logic.showEpisodes(context),
onComments: () => logic.showComments(context, drama),
onComments: () => unawaited(
openCommentsWithAuth(context, drama, show: logic.showComments),
),
onLike: () =>
unawaited(_toggleLike(context, interactions, drama)),
onSave: () => unawaited(_toggleSave(context, drama)),
+28
View File
@@ -69,6 +69,34 @@ void main() {
);
});
testWidgets('should_gate_comments_before_opening_sheet_when_signed_out', (
tester,
) async {
await _pumpApp(tester);
await _openSeriesPlayer(tester);
await tester.tap(find.byKey(const Key('player-rail-comments')));
await tester.pumpAndSettle();
expect(find.text('Sign in to continue'), findsOneWidget);
expect(find.byKey(const Key('player-comments-sheet')), findsNothing);
});
testWidgets('should_open_feed_comments_when_signed_in', (tester) async {
SharedPreferencesAsyncPlatform.instance =
InMemorySharedPreferencesAsync.withData({
'auth.accessToken': 'access',
'auth.refreshToken': 'refresh',
'auth.user': '{"uid":"9","nickname":"Viewer","avatarUrl":""}',
});
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('rail-comments')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('player-comments-sheet')), findsOneWidget);
});
testWidgets('should_show_center_toggle_only_when_paused', (tester) async {
await _pumpApp(tester);
await _openSeriesPlayer(tester);