merge: 合并 K6 登录导航与震动反馈
This commit is contained in:
commit
0cedaab795
28 files changed
+1007
-258
No files matched your search
@@ -33,6 +33,7 @@ import 'core/data/services/favorite_controller.dart';
|
|||||||
import 'core/data/services/interaction_controller.dart';
|
import 'core/data/services/interaction_controller.dart';
|
||||||
import 'core/data/services/playback_session.dart';
|
import 'core/data/services/playback_session.dart';
|
||||||
import 'core/data/services/video_player_port.dart';
|
import 'core/data/services/video_player_port.dart';
|
||||||
|
import 'core/platform/haptics.dart';
|
||||||
import 'core/theme/app_theme.dart';
|
import 'core/theme/app_theme.dart';
|
||||||
import 'l10n/app_localizations.dart';
|
import 'l10n/app_localizations.dart';
|
||||||
import 'pages/home/home_view.dart';
|
import 'pages/home/home_view.dart';
|
||||||
@@ -49,6 +50,7 @@ class LumaDramaApp extends StatefulWidget {
|
|||||||
this.playbackRepository,
|
this.playbackRepository,
|
||||||
this.commentRepository,
|
this.commentRepository,
|
||||||
this.interactionRepository,
|
this.interactionRepository,
|
||||||
|
this.haptics = const FlutterHaptics(),
|
||||||
});
|
});
|
||||||
|
|
||||||
final PlayerFactory playerFactory;
|
final PlayerFactory playerFactory;
|
||||||
@@ -62,6 +64,7 @@ class LumaDramaApp extends StatefulWidget {
|
|||||||
final PlaybackRepository? playbackRepository;
|
final PlaybackRepository? playbackRepository;
|
||||||
final CommentRepository? commentRepository;
|
final CommentRepository? commentRepository;
|
||||||
final InteractionRepository? interactionRepository;
|
final InteractionRepository? interactionRepository;
|
||||||
|
final Haptics haptics;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<LumaDramaApp> createState() => _LumaDramaAppState();
|
State<LumaDramaApp> createState() => _LumaDramaAppState();
|
||||||
@@ -176,6 +179,7 @@ class _LumaDramaAppState extends State<LumaDramaApp> {
|
|||||||
Provider<FavoriteRepository>.value(value: _favorites),
|
Provider<FavoriteRepository>.value(value: _favorites),
|
||||||
Provider<CommentRepository>.value(value: _commentRepository),
|
Provider<CommentRepository>.value(value: _commentRepository),
|
||||||
Provider<InteractionRepository>.value(value: _interactionRepository),
|
Provider<InteractionRepository>.value(value: _interactionRepository),
|
||||||
|
Provider<Haptics>.value(value: widget.haptics),
|
||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => CatalogController(_catalogRepository)..load(),
|
create: (_) => CatalogController(_catalogRepository)..load(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
/// User-action haptic feedback boundary.
|
||||||
|
abstract interface class Haptics {
|
||||||
|
/// Feedback for a selection change.
|
||||||
|
Future<void> selectionClick();
|
||||||
|
|
||||||
|
/// Feedback for a primary action.
|
||||||
|
Future<void> lightImpact();
|
||||||
|
|
||||||
|
/// Feedback for a destructive action.
|
||||||
|
Future<void> mediumImpact();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Default implementation backed by Flutter's platform haptics.
|
||||||
|
class FlutterHaptics implements Haptics {
|
||||||
|
const FlutterHaptics();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> selectionClick() =>
|
||||||
|
_ignoreUnavailable(HapticFeedback.selectionClick);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> lightImpact() => _ignoreUnavailable(HapticFeedback.lightImpact);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> mediumImpact() =>
|
||||||
|
_ignoreUnavailable(HapticFeedback.mediumImpact);
|
||||||
|
|
||||||
|
Future<void> _ignoreUnavailable(Future<void> Function() feedback) async {
|
||||||
|
try {
|
||||||
|
await feedback();
|
||||||
|
} catch (_) {
|
||||||
|
// Haptics are optional and may be unavailable on the target device.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../../l10n/app_localizations.dart';
|
import '../../l10n/app_localizations.dart';
|
||||||
import '../data/services/download_controller.dart';
|
import '../data/services/download_controller.dart';
|
||||||
|
import '../platform/haptics.dart';
|
||||||
import 'auth_gate.dart';
|
import 'auth_gate.dart';
|
||||||
|
|
||||||
/// 详情页与播放页共用的下载授权入口。
|
/// 详情页与播放页共用的下载授权入口。
|
||||||
@@ -16,6 +19,7 @@ Future<void> requestEpisodeDownload(
|
|||||||
) async {
|
) async {
|
||||||
if (!await ensureSignedIn(context)) return;
|
if (!await ensureSignedIn(context)) return;
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final result = await context.read<DownloadController>().grant(episodeId);
|
final result = await context.read<DownloadController>().grant(episodeId);
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
|
|||||||
@@ -253,6 +253,7 @@
|
|||||||
"authSignInTitle": "Welcome back",
|
"authSignInTitle": "Welcome back",
|
||||||
"authSignUpTitle": "Create your account",
|
"authSignUpTitle": "Create your account",
|
||||||
"authSubtitle": "Sign in with your email and password.",
|
"authSubtitle": "Sign in with your email and password.",
|
||||||
|
"authBrandTagline": "Short dramas made for Indonesia",
|
||||||
"authEmailLabel": "Email",
|
"authEmailLabel": "Email",
|
||||||
"authPasswordLabel": "Password",
|
"authPasswordLabel": "Password",
|
||||||
"authPasswordHint": "At least 8 characters, letters and numbers",
|
"authPasswordHint": "At least 8 characters, letters and numbers",
|
||||||
@@ -267,6 +268,8 @@
|
|||||||
"authGateTitle": "Sign in to continue",
|
"authGateTitle": "Sign in to continue",
|
||||||
"authGateMessage": "Watch history, favorites, comments and downloads need an account.",
|
"authGateMessage": "Watch history, favorites, comments and downloads need an account.",
|
||||||
"authGateAction": "Sign In",
|
"authGateAction": "Sign In",
|
||||||
|
"showPassword": "Show password",
|
||||||
|
"hidePassword": "Hide password",
|
||||||
"cancel": "Not now",
|
"cancel": "Not now",
|
||||||
"noEpisodesYet": "No playable episodes yet.",
|
"noEpisodesYet": "No playable episodes yet.",
|
||||||
"networkError": "Network is unreachable. Please check your connection and retry.",
|
"networkError": "Network is unreachable. Please check your connection and retry.",
|
||||||
|
|||||||
@@ -253,6 +253,7 @@
|
|||||||
"authSignInTitle": "Selamat datang kembali",
|
"authSignInTitle": "Selamat datang kembali",
|
||||||
"authSignUpTitle": "Buat akun kamu",
|
"authSignUpTitle": "Buat akun kamu",
|
||||||
"authSubtitle": "Masuk dengan email dan kata sandi.",
|
"authSubtitle": "Masuk dengan email dan kata sandi.",
|
||||||
|
"authBrandTagline": "Drama pendek untuk Indonesia",
|
||||||
"authEmailLabel": "Email",
|
"authEmailLabel": "Email",
|
||||||
"authPasswordLabel": "Kata sandi",
|
"authPasswordLabel": "Kata sandi",
|
||||||
"authPasswordHint": "Minimal 8 karakter, berisi huruf dan angka",
|
"authPasswordHint": "Minimal 8 karakter, berisi huruf dan angka",
|
||||||
@@ -267,6 +268,8 @@
|
|||||||
"authGateTitle": "Masuk untuk melanjutkan",
|
"authGateTitle": "Masuk untuk melanjutkan",
|
||||||
"authGateMessage": "Riwayat tontonan, favorit, komentar, dan unduhan perlu akun.",
|
"authGateMessage": "Riwayat tontonan, favorit, komentar, dan unduhan perlu akun.",
|
||||||
"authGateAction": "Masuk",
|
"authGateAction": "Masuk",
|
||||||
|
"showPassword": "Tampilkan kata sandi",
|
||||||
|
"hidePassword": "Sembunyikan kata sandi",
|
||||||
"cancel": "Nanti saja",
|
"cancel": "Nanti saja",
|
||||||
"noEpisodesYet": "Belum ada episode yang bisa diputar.",
|
"noEpisodesYet": "Belum ada episode yang bisa diputar.",
|
||||||
"networkError": "Jaringan tidak tersedia. Periksa koneksi lalu coba lagi.",
|
"networkError": "Jaringan tidak tersedia. Periksa koneksi lalu coba lagi.",
|
||||||
|
|||||||
@@ -1234,6 +1234,12 @@ abstract class AppLocalizations {
|
|||||||
/// **'Sign in with your email and password.'**
|
/// **'Sign in with your email and password.'**
|
||||||
String get authSubtitle;
|
String get authSubtitle;
|
||||||
|
|
||||||
|
/// No description provided for @authBrandTagline.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Short dramas made for Indonesia'**
|
||||||
|
String get authBrandTagline;
|
||||||
|
|
||||||
/// No description provided for @authEmailLabel.
|
/// No description provided for @authEmailLabel.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
@@ -1318,6 +1324,18 @@ abstract class AppLocalizations {
|
|||||||
/// **'Sign In'**
|
/// **'Sign In'**
|
||||||
String get authGateAction;
|
String get authGateAction;
|
||||||
|
|
||||||
|
/// No description provided for @showPassword.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Show password'**
|
||||||
|
String get showPassword;
|
||||||
|
|
||||||
|
/// No description provided for @hidePassword.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Hide password'**
|
||||||
|
String get hidePassword;
|
||||||
|
|
||||||
/// No description provided for @cancel.
|
/// No description provided for @cancel.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
|
|||||||
@@ -602,6 +602,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authSubtitle => 'Sign in with your email and password.';
|
String get authSubtitle => 'Sign in with your email and password.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authBrandTagline => 'Short dramas made for Indonesia';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authEmailLabel => 'Email';
|
String get authEmailLabel => 'Email';
|
||||||
|
|
||||||
@@ -645,6 +648,12 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authGateAction => 'Sign In';
|
String get authGateAction => 'Sign In';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get showPassword => 'Show password';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get hidePassword => 'Hide password';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get cancel => 'Not now';
|
String get cancel => 'Not now';
|
||||||
|
|
||||||
|
|||||||
@@ -604,6 +604,9 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authSubtitle => 'Masuk dengan email dan kata sandi.';
|
String get authSubtitle => 'Masuk dengan email dan kata sandi.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authBrandTagline => 'Drama pendek untuk Indonesia';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authEmailLabel => 'Email';
|
String get authEmailLabel => 'Email';
|
||||||
|
|
||||||
@@ -647,6 +650,12 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authGateAction => 'Masuk';
|
String get authGateAction => 'Masuk';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get showPassword => 'Tampilkan kata sandi';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get hidePassword => 'Sembunyikan kata sandi';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get cancel => 'Nanti saja';
|
String get cancel => 'Nanti saja';
|
||||||
|
|
||||||
|
|||||||
@@ -593,6 +593,9 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authSubtitle => '用邮箱和密码登录。';
|
String get authSubtitle => '用邮箱和密码登录。';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get authBrandTagline => '为印尼市场打造的短剧体验';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get authEmailLabel => '邮箱';
|
String get authEmailLabel => '邮箱';
|
||||||
|
|
||||||
@@ -635,6 +638,12 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get authGateAction => '去登录';
|
String get authGateAction => '去登录';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get showPassword => '显示密码';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get hidePassword => '隐藏密码';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get cancel => '暂不';
|
String get cancel => '暂不';
|
||||||
|
|
||||||
|
|||||||
@@ -215,6 +215,7 @@
|
|||||||
"authSignInTitle": "欢迎回来",
|
"authSignInTitle": "欢迎回来",
|
||||||
"authSignUpTitle": "创建账号",
|
"authSignUpTitle": "创建账号",
|
||||||
"authSubtitle": "用邮箱和密码登录。",
|
"authSubtitle": "用邮箱和密码登录。",
|
||||||
|
"authBrandTagline": "为印尼市场打造的短剧体验",
|
||||||
"authEmailLabel": "邮箱",
|
"authEmailLabel": "邮箱",
|
||||||
"authPasswordLabel": "密码",
|
"authPasswordLabel": "密码",
|
||||||
"authPasswordHint": "至少 8 位,需包含字母和数字",
|
"authPasswordHint": "至少 8 位,需包含字母和数字",
|
||||||
@@ -229,6 +230,8 @@
|
|||||||
"authGateTitle": "登录后可继续",
|
"authGateTitle": "登录后可继续",
|
||||||
"authGateMessage": "观看记录、收藏、评论和下载需要登录。",
|
"authGateMessage": "观看记录、收藏、评论和下载需要登录。",
|
||||||
"authGateAction": "去登录",
|
"authGateAction": "去登录",
|
||||||
|
"showPassword": "显示密码",
|
||||||
|
"hidePassword": "隐藏密码",
|
||||||
"cancel": "暂不",
|
"cancel": "暂不",
|
||||||
"noEpisodesYet": "还没有可播放的剧集。",
|
"noEpisodesYet": "还没有可播放的剧集。",
|
||||||
"networkError": "网络异常,请检查网络后重试。",
|
"networkError": "网络异常,请检查网络后重试。",
|
||||||
|
|||||||
+243
-133
@@ -1,16 +1,21 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../../core/data/remote/api_client.dart';
|
import '../../core/data/remote/api_client.dart';
|
||||||
import '../../core/data/services/auth_controller.dart';
|
import '../../core/data/services/auth_controller.dart';
|
||||||
|
import '../../core/platform/haptics.dart';
|
||||||
import '../../core/theme/app_colors.dart';
|
import '../../core/theme/app_colors.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../l10n/app_localizations.dart';
|
import '../../l10n/app_localizations.dart';
|
||||||
import 'auth_logic.dart';
|
import 'auth_logic.dart';
|
||||||
|
|
||||||
|
const double _minTapTarget = 44;
|
||||||
|
|
||||||
/// 登录 / 注册页:邮箱 + 密码。
|
/// 登录 / 注册页:邮箱 + 密码。
|
||||||
///
|
|
||||||
/// 风格沿用 FruitShorts 现有页面(深色卡片 + 圆角 + 主色蓝),不另起一套视觉。
|
|
||||||
class AuthPage extends StatefulWidget {
|
class AuthPage extends StatefulWidget {
|
||||||
const AuthPage({super.key, this.signUpMode = false});
|
const AuthPage({super.key, this.signUpMode = false});
|
||||||
|
|
||||||
@@ -22,11 +27,29 @@ class AuthPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _AuthPageState extends State<AuthPage> {
|
class _AuthPageState extends State<AuthPage> {
|
||||||
late AuthLogic _logic;
|
late AuthLogic _logic;
|
||||||
|
late final TextEditingController _emailController;
|
||||||
|
late final TextEditingController _passwordController;
|
||||||
|
late final FocusNode _emailFocus;
|
||||||
|
late final FocusNode _passwordFocus;
|
||||||
|
bool _obscurePassword = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_logic = AuthLogic(signUpMode: widget.signUpMode);
|
_logic = AuthLogic(signUpMode: widget.signUpMode);
|
||||||
|
_emailController = TextEditingController();
|
||||||
|
_passwordController = TextEditingController();
|
||||||
|
_emailFocus = FocusNode(debugLabel: 'auth-email-focus');
|
||||||
|
_passwordFocus = FocusNode(debugLabel: 'auth-password-focus');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_emailController.dispose();
|
||||||
|
_passwordController.dispose();
|
||||||
|
_emailFocus.dispose();
|
||||||
|
_passwordFocus.dispose();
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
String _errorText(AppLocalizations l10n, AuthFieldError error) {
|
String _errorText(AppLocalizations l10n, AuthFieldError error) {
|
||||||
@@ -51,6 +74,8 @@ class _AuthPageState extends State<AuthPage> {
|
|||||||
setState(() => _logic.errorMessage = _errorText(l10n, invalid));
|
setState(() => _logic.errorMessage = _errorText(l10n, invalid));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
setState(() {
|
setState(() {
|
||||||
_logic.busy = true;
|
_logic.busy = true;
|
||||||
_logic.errorMessage = null;
|
_logic.errorMessage = null;
|
||||||
@@ -71,7 +96,6 @@ class _AuthPageState extends State<AuthPage> {
|
|||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.of(context).maybePop();
|
Navigator.of(context).maybePop();
|
||||||
} on ApiException catch (error) {
|
} on ApiException catch (error) {
|
||||||
// 后端文案已经是可直接展示的中文/印尼语提示,错误码不外露
|
|
||||||
setState(() => _logic.errorMessage = error.message);
|
setState(() => _logic.errorMessage = error.message);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
setState(() => _logic.errorMessage = l10n.authNetworkError);
|
setState(() => _logic.errorMessage = l10n.authNetworkError);
|
||||||
@@ -86,158 +110,244 @@ class _AuthPageState extends State<AuthPage> {
|
|||||||
return Theme(
|
return Theme(
|
||||||
data: AppTheme.dark(),
|
data: AppTheme.dark(),
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
resizeToAvoidBottomInset: true,
|
||||||
backgroundColor: AppColors.ink,
|
backgroundColor: AppColors.ink,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: AppColors.ink,
|
backgroundColor: AppColors.ink,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: AppColors.onPrimary,
|
||||||
title: Text(_logic.signUpMode ? l10n.signUp : l10n.signIn),
|
title: Text(_logic.signUpMode ? l10n.signUp : l10n.signIn),
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: ListView(
|
child: AutofillGroup(
|
||||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 28),
|
child: ListView(
|
||||||
children: [
|
key: const Key('auth-scroll'),
|
||||||
Text(
|
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||||
_logic.signUpMode ? l10n.authSignUpTitle : l10n.authSignInTitle,
|
padding: EdgeInsets.fromLTRB(
|
||||||
style: const TextStyle(
|
20,
|
||||||
color: Colors.white,
|
12,
|
||||||
fontSize: 22,
|
20,
|
||||||
fontWeight: FontWeight.w800,
|
28 + MediaQuery.viewInsetsOf(context).bottom,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
children: [
|
||||||
Text(
|
_AuthBrand(tagline: l10n.authBrandTagline),
|
||||||
l10n.authSubtitle,
|
const SizedBox(height: 26),
|
||||||
style: const TextStyle(color: AppColors.muted, fontSize: 13),
|
Text(
|
||||||
),
|
|
||||||
const SizedBox(height: 22),
|
|
||||||
_field(
|
|
||||||
label: l10n.authEmailLabel,
|
|
||||||
hint: 'name@example.com',
|
|
||||||
keyboardType: TextInputType.emailAddress,
|
|
||||||
onChanged: (value) => _logic.email = value,
|
|
||||||
autofocus: true,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 14),
|
|
||||||
_field(
|
|
||||||
label: l10n.authPasswordLabel,
|
|
||||||
hint: l10n.authPasswordHint,
|
|
||||||
obscure: true,
|
|
||||||
onChanged: (value) => _logic.password = value,
|
|
||||||
),
|
|
||||||
if (_logic.errorMessage != null) ...[
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Icon(
|
|
||||||
Icons.error_outline,
|
|
||||||
color: Color(0xFFFF6B6B),
|
|
||||||
size: 16,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
_logic.errorMessage!,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Color(0xFFFF6B6B),
|
|
||||||
fontSize: 13,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 22),
|
|
||||||
SizedBox(
|
|
||||||
height: 48,
|
|
||||||
child: FilledButton(
|
|
||||||
style: FilledButton.styleFrom(
|
|
||||||
backgroundColor: AppColors.blue,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(24),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: _logic.busy ? null : _submit,
|
|
||||||
child: _logic.busy
|
|
||||||
? const SizedBox(
|
|
||||||
width: 18,
|
|
||||||
height: 18,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Text(
|
|
||||||
_logic.signUpMode ? l10n.signUp : l10n.signIn,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 14),
|
|
||||||
TextButton(
|
|
||||||
onPressed: _logic.busy
|
|
||||||
? null
|
|
||||||
: () => setState(() => _logic.toggleMode()),
|
|
||||||
child: Text(
|
|
||||||
_logic.signUpMode
|
_logic.signUpMode
|
||||||
? l10n.authSwitchToSignIn
|
? l10n.authSignUpTitle
|
||||||
: l10n.authSwitchToSignUp,
|
: l10n.authSignInTitle,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: AppColors.blueSoft,
|
color: AppColors.onPrimary,
|
||||||
fontSize: 13,
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.w800,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 6),
|
||||||
],
|
Text(
|
||||||
|
l10n.authSubtitle,
|
||||||
|
style: const TextStyle(color: AppColors.muted, fontSize: 13),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 22),
|
||||||
|
_emailField(l10n),
|
||||||
|
const SizedBox(height: 14),
|
||||||
|
_passwordField(l10n),
|
||||||
|
if (_logic.errorMessage != null) ...[
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
_AuthError(message: _logic.errorMessage!),
|
||||||
|
],
|
||||||
|
const SizedBox(height: 22),
|
||||||
|
_submitButton(l10n),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
_switchModeButton(l10n),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _field({
|
Widget _emailField(AppLocalizations l10n) => _field(
|
||||||
required String label,
|
child: TextField(
|
||||||
required String hint,
|
key: const Key('auth-email'),
|
||||||
required ValueChanged<String> onChanged,
|
controller: _emailController,
|
||||||
bool obscure = false,
|
focusNode: _emailFocus,
|
||||||
bool autofocus = false,
|
enabled: !_logic.busy,
|
||||||
TextInputType? keyboardType,
|
autofocus: true,
|
||||||
}) {
|
keyboardType: TextInputType.emailAddress,
|
||||||
return Column(
|
textInputAction: TextInputAction.next,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
autofillHints: const [AutofillHints.email],
|
||||||
children: [
|
onChanged: (value) => _logic.email = value,
|
||||||
Text(
|
onSubmitted: (_) => _passwordFocus.requestFocus(),
|
||||||
label,
|
style: const TextStyle(color: AppColors.onPrimary, fontSize: 15),
|
||||||
style: const TextStyle(
|
decoration: _decoration(l10n.authEmailLabel, 'name@example.com'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _passwordField(AppLocalizations l10n) => _field(
|
||||||
|
child: TextField(
|
||||||
|
key: const Key('auth-password'),
|
||||||
|
controller: _passwordController,
|
||||||
|
focusNode: _passwordFocus,
|
||||||
|
enabled: !_logic.busy,
|
||||||
|
obscureText: _obscurePassword,
|
||||||
|
keyboardType: TextInputType.visiblePassword,
|
||||||
|
textInputAction: TextInputAction.done,
|
||||||
|
autofillHints: const [AutofillHints.password],
|
||||||
|
onChanged: (value) => _logic.password = value,
|
||||||
|
onSubmitted: (_) => _submit(),
|
||||||
|
style: const TextStyle(color: AppColors.onPrimary, fontSize: 15),
|
||||||
|
decoration: _decoration(
|
||||||
|
l10n.authPasswordLabel,
|
||||||
|
l10n.authPasswordHint,
|
||||||
|
suffix: IconButton(
|
||||||
|
key: const Key('auth-password-visibility'),
|
||||||
|
constraints: const BoxConstraints.tightFor(
|
||||||
|
width: _minTapTarget,
|
||||||
|
height: _minTapTarget,
|
||||||
|
),
|
||||||
|
tooltip: _obscurePassword ? l10n.showPassword : l10n.hidePassword,
|
||||||
|
onPressed: _logic.busy
|
||||||
|
? null
|
||||||
|
: () => setState(() => _obscurePassword = !_obscurePassword),
|
||||||
|
icon: Icon(
|
||||||
|
_obscurePassword
|
||||||
|
? Icons.visibility_outlined
|
||||||
|
: Icons.visibility_off_outlined,
|
||||||
color: AppColors.muted,
|
color: AppColors.muted,
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
),
|
||||||
TextField(
|
),
|
||||||
autofocus: autofocus,
|
);
|
||||||
obscureText: obscure,
|
|
||||||
keyboardType: keyboardType,
|
Widget _field({required Widget child}) =>
|
||||||
onChanged: onChanged,
|
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [child]);
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 15),
|
|
||||||
decoration: InputDecoration(
|
InputDecoration _decoration(String label, String hint, {Widget? suffix}) {
|
||||||
hintText: hint,
|
final scheme = Theme.of(context).colorScheme;
|
||||||
hintStyle: const TextStyle(color: Color(0xFF6C7280), fontSize: 14),
|
return InputDecoration(
|
||||||
filled: true,
|
labelText: label,
|
||||||
fillColor: AppColors.card,
|
hintText: hint,
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
hintStyle: TextStyle(color: scheme.onSurfaceVariant, fontSize: 14),
|
||||||
horizontal: 14,
|
suffixIcon: suffix,
|
||||||
vertical: 14,
|
filled: true,
|
||||||
),
|
fillColor: AppColors.card,
|
||||||
border: OutlineInputBorder(
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 17),
|
||||||
borderRadius: BorderRadius.circular(12),
|
border: OutlineInputBorder(
|
||||||
borderSide: BorderSide.none,
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide.none,
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
borderSide: BorderSide(color: scheme.primary, width: 1.5),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _submitButton(AppLocalizations l10n) => SizedBox(
|
||||||
|
height: 50,
|
||||||
|
child: FilledButton(
|
||||||
|
key: const Key('auth-submit'),
|
||||||
|
onPressed: _logic.busy ? null : _submit,
|
||||||
|
style: FilledButton.styleFrom(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
|
||||||
|
),
|
||||||
|
child: _logic.busy
|
||||||
|
? const SizedBox.square(
|
||||||
|
dimension: 18,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
color: AppColors.onPrimary,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
_logic.signUpMode ? l10n.signUp : l10n.signIn,
|
||||||
|
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w700),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _switchModeButton(AppLocalizations l10n) => TextButton(
|
||||||
|
key: const Key('auth-switch-mode'),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
minimumSize: const Size(0, _minTapTarget),
|
||||||
|
foregroundColor: AppColors.blueSoft,
|
||||||
|
),
|
||||||
|
onPressed: _logic.busy ? null : () => setState(() => _logic.toggleMode()),
|
||||||
|
child: Text(
|
||||||
|
_logic.signUpMode ? l10n.authSwitchToSignIn : l10n.authSwitchToSignUp,
|
||||||
|
style: const TextStyle(fontSize: 13),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AuthBrand extends StatelessWidget {
|
||||||
|
const _AuthBrand({required this.tagline});
|
||||||
|
|
||||||
|
final String tagline;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: AppColors.blue,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.play_arrow_rounded,
|
||||||
|
color: AppColors.onPrimary,
|
||||||
|
size: 30,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
AppLocalizations.of(context)!.appName,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: AppColors.onPrimary,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.w800,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 2),
|
||||||
|
Text(
|
||||||
|
tagline,
|
||||||
|
style: const TextStyle(color: AppColors.blueSoft, fontSize: 12),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AuthError extends StatelessWidget {
|
||||||
|
const _AuthError({required this.message});
|
||||||
|
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final color = Theme.of(context).colorScheme.error;
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.error_outline, color: color, size: 18),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
message,
|
||||||
|
key: const Key('auth-error'),
|
||||||
|
style: TextStyle(color: color, fontSize: 13),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import '../../core/data/services/auth_controller.dart';
|
|||||||
import '../../core/data/services/download_controller.dart';
|
import '../../core/data/services/download_controller.dart';
|
||||||
import '../../core/formatting/error_text.dart';
|
import '../../core/formatting/error_text.dart';
|
||||||
import '../../core/formatting/localized_date_time.dart';
|
import '../../core/formatting/localized_date_time.dart';
|
||||||
|
import '../../core/platform/haptics.dart';
|
||||||
import '../../core/theme/app_colors.dart';
|
import '../../core/theme/app_colors.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/widgets/auth_gate.dart';
|
import '../../core/widgets/auth_gate.dart';
|
||||||
@@ -166,6 +167,7 @@ class _DownloadsBody extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _remove(BuildContext context, String episodeId) async {
|
Future<void> _remove(BuildContext context, String episodeId) async {
|
||||||
|
unawaited(context.read<Haptics>().mediumImpact());
|
||||||
final ok = await downloads.remove(episodeId);
|
final ok = await downloads.remove(episodeId);
|
||||||
if (ok || !context.mounted) return;
|
if (ok || !context.mounted) return;
|
||||||
_showMessage(context, AppLocalizations.of(context)!.downloadDeleteFailed);
|
_showMessage(context, AppLocalizations.of(context)!.downloadDeleteFailed);
|
||||||
@@ -191,6 +193,9 @@ class _DownloadsBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (confirmed != true) return;
|
if (confirmed != true) return;
|
||||||
|
if (context.mounted) {
|
||||||
|
unawaited(context.read<Haptics>().mediumImpact());
|
||||||
|
}
|
||||||
final ok = await downloads.clear();
|
final ok = await downloads.clear();
|
||||||
if (!ok && context.mounted) {
|
if (!ok && context.mounted) {
|
||||||
_showMessage(context, l10n.downloadClearFailed);
|
_showMessage(context, l10n.downloadClearFailed);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import '../../core/data/services/favorite_controller.dart';
|
|||||||
import '../../core/data/services/interaction_controller.dart';
|
import '../../core/data/services/interaction_controller.dart';
|
||||||
import '../../core/formatting/error_text.dart';
|
import '../../core/formatting/error_text.dart';
|
||||||
import '../../core/formatting/localized_content.dart';
|
import '../../core/formatting/localized_content.dart';
|
||||||
|
import '../../core/platform/haptics.dart';
|
||||||
import '../../core/theme/app_colors.dart';
|
import '../../core/theme/app_colors.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/widgets/remote_image.dart';
|
import '../../core/widgets/remote_image.dart';
|
||||||
@@ -315,6 +316,7 @@ class _DramaDetailPageState extends State<DramaDetailPage> {
|
|||||||
if (!await ensureSignedIn(context) || !mounted) return;
|
if (!await ensureSignedIn(context) || !mounted) return;
|
||||||
final draft = await showReportDialog(context, title: l10n.reportDrama);
|
final draft = await showReportDialog(context, title: l10n.reportDrama);
|
||||||
if (draft == null || !mounted) return;
|
if (draft == null || !mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final result = await context.read<InteractionController>().reportDrama(
|
final result = await context.read<InteractionController>().reportDrama(
|
||||||
logic.drama.id,
|
logic.drama.id,
|
||||||
reason: draft.reason,
|
reason: draft.reason,
|
||||||
@@ -341,6 +343,8 @@ class _DramaDetailPageState extends State<DramaDetailPage> {
|
|||||||
icon: Icon(saved ? Icons.bookmark : Icons.bookmark_border),
|
icon: Icon(saved ? Icons.bookmark : Icons.bookmark_border),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (!await ensureSignedIn(context)) return;
|
if (!await ensureSignedIn(context)) return;
|
||||||
|
if (!context.mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final ok = await logic.toggleFavorite();
|
final ok = await logic.toggleFavorite();
|
||||||
if (ok || !context.mounted) return;
|
if (ok || !context.mounted) return;
|
||||||
// 成功靠图标变化反馈;失败必须说清楚(乐观更新已回滚)
|
// 成功靠图标变化反馈;失败必须说清楚(乐观更新已回滚)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import '../../core/data/models/drama.dart';
|
|||||||
import '../../core/data/services/auth_controller.dart';
|
import '../../core/data/services/auth_controller.dart';
|
||||||
import '../../core/data/services/favorite_controller.dart';
|
import '../../core/data/services/favorite_controller.dart';
|
||||||
import '../../core/formatting/error_text.dart';
|
import '../../core/formatting/error_text.dart';
|
||||||
|
import '../../core/platform/haptics.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/widgets/auth_gate.dart';
|
import '../../core/widgets/auth_gate.dart';
|
||||||
import '../../core/widgets/library_drama_tile.dart';
|
import '../../core/widgets/library_drama_tile.dart';
|
||||||
@@ -142,6 +143,7 @@ class _FavoritesBody extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _remove(BuildContext context, String dramaId) async {
|
Future<void> _remove(BuildContext context, String dramaId) async {
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final ok = await favorites.remove(dramaId);
|
final ok = await favorites.remove(dramaId);
|
||||||
if (ok || !context.mounted) return;
|
if (ok || !context.mounted) return;
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -8,6 +10,7 @@ import '../../core/config/app_config.dart';
|
|||||||
import '../../core/data/models/drama.dart';
|
import '../../core/data/models/drama.dart';
|
||||||
import '../../core/data/services/auth_controller.dart';
|
import '../../core/data/services/auth_controller.dart';
|
||||||
import '../../core/data/services/catalog_controller.dart';
|
import '../../core/data/services/catalog_controller.dart';
|
||||||
|
import '../../core/platform/haptics.dart';
|
||||||
import '../../core/theme/app_colors.dart';
|
import '../../core/theme/app_colors.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/widgets/auth_gate.dart';
|
import '../../core/widgets/auth_gate.dart';
|
||||||
@@ -118,7 +121,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
|||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
key: logic.scaffoldKey,
|
key: logic.scaffoldKey,
|
||||||
backgroundColor: const Color(0xFF0B0C10),
|
backgroundColor: AppColors.ink,
|
||||||
drawer: HomeQuickDrawer(
|
drawer: HomeQuickDrawer(
|
||||||
drama: logic.currentDrama,
|
drama: logic.currentDrama,
|
||||||
onOpenSeries: () => logic.openCurrentSeries(context),
|
onOpenSeries: () => logic.openCurrentSeries(context),
|
||||||
@@ -183,12 +186,17 @@ class _HomeTabsState extends State<_HomeTabs> {
|
|||||||
? null
|
? null
|
||||||
: SafeArea(
|
: SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
|
minimum: const EdgeInsets.only(bottom: 2),
|
||||||
child: Container(
|
child: Container(
|
||||||
key: const Key('home-tabs-bar'),
|
key: const Key('home-tabs-bar'),
|
||||||
height: 63,
|
height: 64,
|
||||||
decoration: const BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color(0xFF0D0D11),
|
color: AppColors.bar,
|
||||||
border: Border(top: BorderSide(color: Color(0xFF242329))),
|
border: Border(
|
||||||
|
top: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.outlineVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
@@ -198,7 +206,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
|||||||
selectedIcon: Icons.home_rounded,
|
selectedIcon: Icons.home_rounded,
|
||||||
label: l10n.homeTab,
|
label: l10n.homeTab,
|
||||||
selected: logic.tab == 1,
|
selected: logic.tab == 1,
|
||||||
onTap: () => logic.select(1),
|
onTap: () => _selectTab(context, 1),
|
||||||
),
|
),
|
||||||
_TabButton(
|
_TabButton(
|
||||||
key: const Key('tab-home'),
|
key: const Key('tab-home'),
|
||||||
@@ -206,7 +214,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
|||||||
selectedIcon: Icons.movie_rounded,
|
selectedIcon: Icons.movie_rounded,
|
||||||
label: l10n.shortsTab,
|
label: l10n.shortsTab,
|
||||||
selected: logic.tab == 0,
|
selected: logic.tab == 0,
|
||||||
onTap: () => logic.select(0),
|
onTap: () => _selectTab(context, 0),
|
||||||
),
|
),
|
||||||
_TabButton(
|
_TabButton(
|
||||||
key: const Key('tab-my-list'),
|
key: const Key('tab-my-list'),
|
||||||
@@ -214,7 +222,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
|||||||
selectedIcon: Icons.bookmark_rounded,
|
selectedIcon: Icons.bookmark_rounded,
|
||||||
label: l10n.myListTab,
|
label: l10n.myListTab,
|
||||||
selected: logic.tab == 2 && !logic.profile,
|
selected: logic.tab == 2 && !logic.profile,
|
||||||
onTap: logic.openLibrary,
|
onTap: () => _selectTab(context, 2),
|
||||||
),
|
),
|
||||||
_TabButton(
|
_TabButton(
|
||||||
key: const Key('tab-my'),
|
key: const Key('tab-my'),
|
||||||
@@ -222,7 +230,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
|||||||
selectedIcon: Icons.person_rounded,
|
selectedIcon: Icons.person_rounded,
|
||||||
label: l10n.myTab,
|
label: l10n.myTab,
|
||||||
selected: logic.tab == 2 && logic.profile,
|
selected: logic.tab == 2 && logic.profile,
|
||||||
onTap: logic.openProfile,
|
onTap: () => _selectTab(context, 2, myProfile: true),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -231,6 +239,20 @@ class _HomeTabsState extends State<_HomeTabs> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _selectTab(BuildContext context, int tab, {bool myProfile = false}) {
|
||||||
|
final same = tab == 2
|
||||||
|
? logic.tab == 2 && logic.profile == myProfile
|
||||||
|
: logic.tab == tab;
|
||||||
|
if (!same) {
|
||||||
|
unawaited(context.read<Haptics>().selectionClick());
|
||||||
|
}
|
||||||
|
if (tab == 2) {
|
||||||
|
myProfile ? logic.openProfile() : logic.openLibrary();
|
||||||
|
} else {
|
||||||
|
logic.select(tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TabButton extends StatelessWidget {
|
class _TabButton extends StatelessWidget {
|
||||||
@@ -250,37 +272,48 @@ class _TabButton extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Expanded(
|
Widget build(BuildContext context) => Expanded(
|
||||||
child: InkWell(
|
child: Semantics(
|
||||||
onTap: onTap,
|
button: true,
|
||||||
child: Column(
|
selected: selected,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
label: label,
|
||||||
children: [
|
child: InkWell(
|
||||||
Container(
|
onTap: onTap,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 3),
|
child: ConstrainedBox(
|
||||||
decoration: selected
|
constraints: const BoxConstraints(minHeight: 48),
|
||||||
? BoxDecoration(
|
child: Column(
|
||||||
color: AppColors.bluePressed,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
borderRadius: BorderRadius.circular(14),
|
children: [
|
||||||
)
|
AnimatedContainer(
|
||||||
: null,
|
duration: const Duration(milliseconds: 160),
|
||||||
child: Icon(
|
curve: Curves.easeOut,
|
||||||
selected ? selectedIcon : icon,
|
padding: const EdgeInsets.symmetric(
|
||||||
size: 20,
|
horizontal: 14,
|
||||||
color: selected ? Colors.white : AppColors.muted,
|
vertical: 3,
|
||||||
),
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: selected ? AppColors.bluePressed : null,
|
||||||
|
borderRadius: BorderRadius.circular(14),
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
selected ? selectedIcon : icon,
|
||||||
|
size: 22,
|
||||||
|
color: selected ? AppColors.onPrimary : AppColors.muted,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 2),
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||||
|
color: selected ? AppColors.blueSoft : AppColors.muted,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 2),
|
),
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 10,
|
|
||||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
|
||||||
color: selected ? AppColors.blueSoft : AppColors.muted,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import '../../core/data/services/playback_session.dart';
|
|||||||
import '../../core/data/services/video_player_port.dart';
|
import '../../core/data/services/video_player_port.dart';
|
||||||
import '../../core/formatting/error_text.dart';
|
import '../../core/formatting/error_text.dart';
|
||||||
import '../../core/formatting/localized_content.dart';
|
import '../../core/formatting/localized_content.dart';
|
||||||
|
import '../../core/platform/haptics.dart';
|
||||||
import '../../core/theme/app_colors.dart';
|
import '../../core/theme/app_colors.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/widgets/auth_gate.dart';
|
import '../../core/widgets/auth_gate.dart';
|
||||||
@@ -350,6 +351,8 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
|
|||||||
// 收藏/点赞要对到具体账号:未登录先引导登录(首页/详情仍可匿名浏览)
|
// 收藏/点赞要对到具体账号:未登录先引导登录(首页/详情仍可匿名浏览)
|
||||||
onLike: () async {
|
onLike: () async {
|
||||||
if (await ensureSignedIn(context)) {
|
if (await ensureSignedIn(context)) {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final result = await interactions.toggleDramaLike(drama.id);
|
final result = await interactions.toggleDramaLike(drama.id);
|
||||||
if (!result.isSuccess && context.mounted) {
|
if (!result.isSuccess && context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@@ -366,6 +369,8 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
|
|||||||
onSave: () async {
|
onSave: () async {
|
||||||
final favorites = context.read<FavoriteController>();
|
final favorites = context.read<FavoriteController>();
|
||||||
if (await ensureSignedIn(context)) {
|
if (await ensureSignedIn(context)) {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final ok = await favorites.toggle(drama.id, card: drama);
|
final ok = await favorites.toggle(drama.id, card: drama);
|
||||||
if (ok || !context.mounted) return;
|
if (ok || !context.mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import '../../../core/data/repositories/comment_repository.dart';
|
|||||||
import '../../../core/data/repositories/interaction_repository.dart';
|
import '../../../core/data/repositories/interaction_repository.dart';
|
||||||
import '../../../core/data/services/comment_controller.dart';
|
import '../../../core/data/services/comment_controller.dart';
|
||||||
import '../../../core/formatting/error_text.dart';
|
import '../../../core/formatting/error_text.dart';
|
||||||
|
import '../../../core/platform/haptics.dart';
|
||||||
import '../../../core/theme/app_colors.dart';
|
import '../../../core/theme/app_colors.dart';
|
||||||
import '../../../core/widgets/auth_gate.dart';
|
import '../../../core/widgets/auth_gate.dart';
|
||||||
import '../../../l10n/app_localizations.dart';
|
import '../../../l10n/app_localizations.dart';
|
||||||
@@ -60,6 +61,7 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
|||||||
if (_controller.submitting) return;
|
if (_controller.submitting) return;
|
||||||
if (_input.text.trim().isEmpty) return;
|
if (_input.text.trim().isEmpty) return;
|
||||||
if (!await ensureSignedIn(context) || !mounted) return;
|
if (!await ensureSignedIn(context) || !mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final result = await _controller.publish(_input.text, replyTo: _replyTo);
|
final result = await _controller.publish(_input.text, replyTo: _replyTo);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
@@ -84,6 +86,7 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
|||||||
|
|
||||||
Future<void> _like(DramaComment comment) async {
|
Future<void> _like(DramaComment comment) async {
|
||||||
if (!await ensureSignedIn(context) || !mounted) return;
|
if (!await ensureSignedIn(context) || !mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final result = await _controller.toggleLike(comment);
|
final result = await _controller.toggleLike(comment);
|
||||||
if (!result.isSuccess && mounted) {
|
if (!result.isSuccess && mounted) {
|
||||||
_showMessage(
|
_showMessage(
|
||||||
@@ -116,7 +119,8 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
|||||||
final result = await _controller.delete(comment);
|
final result = await _controller.delete(comment);
|
||||||
if (!result.isSuccess && mounted) {
|
if (!result.isSuccess && mounted) {
|
||||||
_showMessage(
|
_showMessage(
|
||||||
result.errorMessage ?? AppLocalizations.of(context)!.commentDeleteFailed,
|
result.errorMessage ??
|
||||||
|
AppLocalizations.of(context)!.commentDeleteFailed,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,6 +130,7 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
|||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
final draft = await showReportDialog(context, title: l10n.reportComment);
|
final draft = await showReportDialog(context, title: l10n.reportComment);
|
||||||
if (draft == null || !mounted) return;
|
if (draft == null || !mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().lightImpact());
|
||||||
final result = await _controller.report(
|
final result = await _controller.report(
|
||||||
comment,
|
comment,
|
||||||
reason: draft.reason,
|
reason: draft.reason,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import '../../core/data/services/auth_controller.dart';
|
|||||||
import '../../core/data/services/watch_records_controller.dart';
|
import '../../core/data/services/watch_records_controller.dart';
|
||||||
import '../../core/formatting/error_text.dart';
|
import '../../core/formatting/error_text.dart';
|
||||||
import '../../core/formatting/localized_date_time.dart';
|
import '../../core/formatting/localized_date_time.dart';
|
||||||
|
import '../../core/platform/haptics.dart';
|
||||||
import '../../core/theme/app_colors.dart';
|
import '../../core/theme/app_colors.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/widgets/auth_gate.dart';
|
import '../../core/widgets/auth_gate.dart';
|
||||||
@@ -141,6 +142,7 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _remove(String dramaId) async {
|
Future<void> _remove(String dramaId) async {
|
||||||
|
unawaited(context.read<Haptics>().mediumImpact());
|
||||||
final ok = await controller.remove(dramaId);
|
final ok = await controller.remove(dramaId);
|
||||||
if (!ok && mounted) _showFailure('recordDeleteFailed');
|
if (!ok && mounted) _showFailure('recordDeleteFailed');
|
||||||
}
|
}
|
||||||
@@ -164,7 +166,8 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (confirmed != true) return;
|
if (confirmed != true || !mounted) return;
|
||||||
|
unawaited(context.read<Haptics>().mediumImpact());
|
||||||
final ok = await controller.clear();
|
final ok = await controller.clear();
|
||||||
if (!ok && mounted) _showFailure('recordClearFailed');
|
if (!ok && mounted) _showFailure('recordClearFailed');
|
||||||
}
|
}
|
||||||
|
|||||||
+233
-23
@@ -1,17 +1,22 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||||
|
|
||||||
|
import 'package:fruitshorts/core/data/models/auth_session.dart';
|
||||||
import 'package:fruitshorts/core/data/remote/auth_api.dart';
|
import 'package:fruitshorts/core/data/remote/auth_api.dart';
|
||||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||||
|
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||||
import 'package:fruitshorts/pages/auth/auth_view.dart';
|
import 'package:fruitshorts/pages/auth/auth_view.dart';
|
||||||
|
|
||||||
import '../support/fake_http_adapter.dart';
|
import '../support/fake_http_adapter.dart';
|
||||||
|
import '../support/fake_haptics.dart';
|
||||||
|
|
||||||
/// 登录/注册页的可读证据:校验提示 + 登录/注册切换 + 未登录时不会去发请求。
|
/// 登录/注册页的可读证据:校验提示 + 登录/注册切换 + 未登录时不会去发请求。
|
||||||
void main() {
|
void main() {
|
||||||
@@ -20,20 +25,31 @@ void main() {
|
|||||||
InMemorySharedPreferencesAsync.empty();
|
InMemorySharedPreferencesAsync.empty();
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> pumpAuthPage(WidgetTester tester, {bool signUp = false}) async {
|
Future<void> pumpAuthPage(
|
||||||
|
WidgetTester tester, {
|
||||||
|
bool signUp = false,
|
||||||
|
AuthApi? api,
|
||||||
|
FakeHaptics? haptics,
|
||||||
|
}) async {
|
||||||
final auth = AuthController(
|
final auth = AuthController(
|
||||||
AuthApi(
|
api ??
|
||||||
// 这个测试不联网:请求一律 500,正好用于验证"本地校验没过就不发请求"
|
AuthApi(
|
||||||
ApiClient(
|
// 这个测试不联网:请求一律 500,正好用于验证"本地校验没过就不发请求"
|
||||||
baseUrl: 'http://127.0.0.1:1',
|
ApiClient(
|
||||||
adapter: FakeHttpAdapter((_) async => FakeHttpResponse('{}', 500)),
|
baseUrl: 'http://127.0.0.1:1',
|
||||||
),
|
adapter: FakeHttpAdapter(
|
||||||
),
|
(_) async => FakeHttpResponse('{}', 500),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
AuthSessionStore(),
|
AuthSessionStore(),
|
||||||
);
|
);
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
ChangeNotifierProvider<AuthController>.value(
|
MultiProvider(
|
||||||
value: auth,
|
providers: [
|
||||||
|
ChangeNotifierProvider<AuthController>.value(value: auth),
|
||||||
|
Provider<Haptics>.value(value: haptics ?? FakeHaptics()),
|
||||||
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
locale: const Locale('en'),
|
locale: const Locale('en'),
|
||||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
@@ -45,7 +61,9 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
|
||||||
testWidgets('should_show_email_error_and_stay_on_page_when_form_is_empty', (tester) async {
|
testWidgets('should_show_email_error_and_stay_on_page_when_form_is_empty', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
await pumpAuthPage(tester);
|
await pumpAuthPage(tester);
|
||||||
|
|
||||||
expect(find.text('Welcome back'), findsOneWidget);
|
expect(find.text('Welcome back'), findsOneWidget);
|
||||||
@@ -57,25 +75,217 @@ void main() {
|
|||||||
expect(find.text('Welcome back'), findsOneWidget);
|
expect(find.text('Welcome back'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('should_reject_weak_password_locally_when_only_letters_are_typed', (tester) async {
|
testWidgets(
|
||||||
|
'should_reject_weak_password_locally_when_only_letters_are_typed',
|
||||||
|
(tester) async {
|
||||||
|
await pumpAuthPage(tester);
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField).first, 'a@b.com');
|
||||||
|
await tester.enterText(find.byType(TextField).last, 'abcdefgh');
|
||||||
|
await tester.tap(find.byType(FilledButton));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.text('Password needs both letters and numbers'),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'should_flip_between_sign_in_and_sign_up_when_switch_link_is_tapped',
|
||||||
|
(tester) async {
|
||||||
|
await pumpAuthPage(tester);
|
||||||
|
expect(find.text('Welcome back'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.text('New here? Create an account'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('Create your account'), findsOneWidget);
|
||||||
|
expect(find.text('Already have an account? Sign in'), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets('should_show_brand_and_form_accessibility_when_page_opens', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
await pumpAuthPage(tester);
|
await pumpAuthPage(tester);
|
||||||
|
|
||||||
await tester.enterText(find.byType(TextField).first, 'a@b.com');
|
expect(find.text('FruitShorts'), findsOneWidget);
|
||||||
await tester.enterText(find.byType(TextField).last, 'abcdefgh');
|
expect(find.text('Short dramas made for Indonesia'), findsOneWidget);
|
||||||
await tester.tap(find.byType(FilledButton));
|
final email = tester.widget<TextField>(find.byKey(const Key('auth-email')));
|
||||||
await tester.pumpAndSettle();
|
final password = tester.widget<TextField>(
|
||||||
|
find.byKey(const Key('auth-password')),
|
||||||
expect(find.text('Password needs both letters and numbers'), findsOneWidget);
|
);
|
||||||
|
expect(email.autofillHints, contains(AutofillHints.email));
|
||||||
|
expect(password.autofillHints, contains(AutofillHints.password));
|
||||||
|
expect(
|
||||||
|
tester.getSize(find.byKey(const Key('auth-submit'))).height,
|
||||||
|
greaterThanOrEqualTo(44),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.getSize(find.byKey(const Key('auth-password-visibility'))).height,
|
||||||
|
greaterThanOrEqualTo(44),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.getSize(find.byKey(const Key('auth-switch-mode'))).height,
|
||||||
|
greaterThanOrEqualTo(44),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('should_flip_between_sign_in_and_sign_up_when_switch_link_is_tapped', (tester) async {
|
testWidgets('should_toggle_password_visibility_when_eye_button_is_tapped', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
await pumpAuthPage(tester);
|
await pumpAuthPage(tester);
|
||||||
expect(find.text('Welcome back'), findsOneWidget);
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<TextField>(find.byKey(const Key('auth-password')))
|
||||||
|
.obscureText,
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
|
||||||
await tester.tap(find.text('New here? Create an account'));
|
await tester.tap(find.byKey(const Key('auth-password-visibility')));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<TextField>(find.byKey(const Key('auth-password')))
|
||||||
|
.obscureText,
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
expect(find.byTooltip('Hide password'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should_move_focus_from_email_to_password_when_next_is_pressed', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpAuthPage(tester);
|
||||||
|
await tester.tap(find.byKey(const Key('auth-email')));
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.next);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
FocusManager.instance.primaryFocus?.debugLabel,
|
||||||
|
'auth-password-focus',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should_disable_form_and_submit_while_done_action_is_pending', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final api = _PendingAuthApi();
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
await pumpAuthPage(tester, api: api, haptics: haptics);
|
||||||
|
await tester.enterText(find.byKey(const Key('auth-email')), 'a@b.com');
|
||||||
|
await tester.enterText(find.byKey(const Key('auth-password')), 'abcd1234');
|
||||||
|
await tester.tap(find.byKey(const Key('auth-password')));
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(api.loginCalls, 1);
|
||||||
|
expect(haptics.lightImpacts, 1);
|
||||||
|
expect(
|
||||||
|
tester.widget<TextField>(find.byKey(const Key('auth-email'))).enabled,
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.widget<TextField>(find.byKey(const Key('auth-password'))).enabled,
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<IconButton>(find.byKey(const Key('auth-password-visibility')))
|
||||||
|
.onPressed,
|
||||||
|
isNull,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<FilledButton>(find.byKey(const Key('auth-submit')))
|
||||||
|
.onPressed,
|
||||||
|
isNull,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<TextButton>(find.byKey(const Key('auth-switch-mode')))
|
||||||
|
.onPressed,
|
||||||
|
isNull,
|
||||||
|
);
|
||||||
|
|
||||||
|
api.release();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should_render_validation_error_with_theme_semantic_color', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpAuthPage(tester);
|
||||||
|
await tester.enterText(find.byKey(const Key('auth-email')), 'a@b.com');
|
||||||
|
await tester.enterText(find.byKey(const Key('auth-password')), 'abcdefgh');
|
||||||
|
await tester.tap(find.byKey(const Key('auth-submit')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text('Create your account'), findsOneWidget);
|
final errorFinder = find.byKey(const Key('auth-error'));
|
||||||
expect(find.text('Already have an account? Sign in'), findsOneWidget);
|
final error = tester.widget<Text>(errorFinder);
|
||||||
|
final expected = Theme.of(tester.element(errorFinder)).colorScheme.error;
|
||||||
|
expect(error.style?.color, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'should_keep_submit_reachable_when_keyboard_opens_on_small_screen',
|
||||||
|
(tester) async {
|
||||||
|
tester.view.physicalSize = const Size(320, 568);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
tester.view.viewInsets = const FakeViewPadding(bottom: 260);
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
addTearDown(tester.view.resetViewInsets);
|
||||||
|
|
||||||
|
await pumpAuthPage(tester);
|
||||||
|
await tester.scrollUntilVisible(
|
||||||
|
find.byKey(const Key('auth-submit')),
|
||||||
|
120,
|
||||||
|
scrollable: find
|
||||||
|
.descendant(
|
||||||
|
of: find.byKey(const Key('auth-scroll')),
|
||||||
|
matching: find.byType(Scrollable),
|
||||||
|
)
|
||||||
|
.first,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.byKey(const Key('auth-submit')).hitTestable(),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PendingAuthApi extends AuthApi {
|
||||||
|
_PendingAuthApi()
|
||||||
|
: super(
|
||||||
|
ApiClient(
|
||||||
|
baseUrl: 'http://127.0.0.1:1',
|
||||||
|
adapter: FakeHttpAdapter((_) async => FakeHttpResponse('{}', 500)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final _gate = Completer<void>();
|
||||||
|
int loginCalls = 0;
|
||||||
|
|
||||||
|
void release() => _gate.complete();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AuthSession> login({
|
||||||
|
required String email,
|
||||||
|
required String password,
|
||||||
|
required String deviceId,
|
||||||
|
String platform = '',
|
||||||
|
String appVersion = '',
|
||||||
|
}) async {
|
||||||
|
loginCalls++;
|
||||||
|
await _gate.future;
|
||||||
|
throw const ApiException(500, 'pending failure');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ import 'package:fruitshorts/core/data/repositories/comment_repository.dart';
|
|||||||
import 'package:fruitshorts/core/data/repositories/interaction_repository.dart';
|
import 'package:fruitshorts/core/data/repositories/interaction_repository.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||||
|
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||||
import 'package:fruitshorts/pages/player/widgets/drama_comments_sheet.dart';
|
import 'package:fruitshorts/pages/player/widgets/drama_comments_sheet.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -18,6 +19,7 @@ import 'package:shared_preferences_platform_interface/in_memory_shared_preferenc
|
|||||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||||
|
|
||||||
import '../support/fake_http_adapter.dart';
|
import '../support/fake_http_adapter.dart';
|
||||||
|
import '../support/fake_haptics.dart';
|
||||||
import '../support/fake_interaction_repositories.dart';
|
import '../support/fake_interaction_repositories.dart';
|
||||||
|
|
||||||
const _drama = Drama(
|
const _drama = Drama(
|
||||||
@@ -66,28 +68,29 @@ void main() {
|
|||||||
expect(repository.pageCalls.last.cursor, '10');
|
expect(repository.pageCalls.last.cursor, '10');
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('should_keep_input_and_show_backend_message_when_comment_is_blocked', (
|
testWidgets(
|
||||||
tester,
|
'should_keep_input_and_show_backend_message_when_comment_is_blocked',
|
||||||
) async {
|
(tester) async {
|
||||||
final repository = FakeCommentRepository(
|
final repository = FakeCommentRepository(
|
||||||
pages: [const CommentPage()],
|
pages: [const CommentPage()],
|
||||||
publishError: const ApiException(400, '评论包含敏感词'),
|
publishError: const ApiException(400, '评论包含敏感词'),
|
||||||
);
|
);
|
||||||
|
|
||||||
await _pumpSheet(tester, repository: repository);
|
await _pumpSheet(tester, repository: repository);
|
||||||
await tester.enterText(
|
await tester.enterText(
|
||||||
find.byKey(const Key('comment-input')),
|
find.byKey(const Key('comment-input')),
|
||||||
'blocked text',
|
'blocked text',
|
||||||
);
|
);
|
||||||
await tester.tap(find.byKey(const Key('comment-post')));
|
await tester.tap(find.byKey(const Key('comment-post')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text('评论包含敏感词'), findsOneWidget);
|
expect(find.text('评论包含敏感词'), findsOneWidget);
|
||||||
final field = tester.widget<TextField>(
|
final field = tester.widget<TextField>(
|
||||||
find.byKey(const Key('comment-input')),
|
find.byKey(const Key('comment-input')),
|
||||||
);
|
);
|
||||||
expect(field.controller?.text, 'blocked text');
|
expect(field.controller?.text, 'blocked text');
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('should_show_review_badge_and_server_replaced_content', (
|
testWidgets('should_show_review_badge_and_server_replaced_content', (
|
||||||
tester,
|
tester,
|
||||||
@@ -101,8 +104,9 @@ void main() {
|
|||||||
mine: true,
|
mine: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
|
||||||
await _pumpSheet(tester, repository: repository);
|
await _pumpSheet(tester, repository: repository, haptics: haptics);
|
||||||
await tester.enterText(
|
await tester.enterText(
|
||||||
find.byKey(const Key('comment-input')),
|
find.byKey(const Key('comment-input')),
|
||||||
'hello badword',
|
'hello badword',
|
||||||
@@ -112,6 +116,7 @@ void main() {
|
|||||||
|
|
||||||
expect(find.text('hello ***'), findsOneWidget);
|
expect(find.text('hello ***'), findsOneWidget);
|
||||||
expect(find.text('Under review'), findsOneWidget);
|
expect(find.text('Under review'), findsOneWidget);
|
||||||
|
expect(haptics.lightImpacts, 1);
|
||||||
final field = tester.widget<TextField>(
|
final field = tester.widget<TextField>(
|
||||||
find.byKey(const Key('comment-input')),
|
find.byKey(const Key('comment-input')),
|
||||||
);
|
);
|
||||||
@@ -139,10 +144,7 @@ void main() {
|
|||||||
await tester.tap(find.byKey(const Key('comment-reply-10')));
|
await tester.tap(find.byKey(const Key('comment-reply-10')));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.textContaining('Replying to'), findsOneWidget);
|
expect(find.textContaining('Replying to'), findsOneWidget);
|
||||||
await tester.enterText(
|
await tester.enterText(find.byKey(const Key('comment-input')), 'My reply');
|
||||||
find.byKey(const Key('comment-input')),
|
|
||||||
'My reply',
|
|
||||||
);
|
|
||||||
await tester.tap(find.byKey(const Key('comment-post')));
|
await tester.tap(find.byKey(const Key('comment-post')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
@@ -153,9 +155,7 @@ void main() {
|
|||||||
testWidgets('should_show_error_and_retry_when_comment_page_fails', (
|
testWidgets('should_show_error_and_retry_when_comment_page_fails', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
final repository = FakeCommentRepository(
|
final repository = FakeCommentRepository(pageError: StateError('offline'));
|
||||||
pageError: StateError('offline'),
|
|
||||||
);
|
|
||||||
|
|
||||||
await _pumpSheet(tester, repository: repository);
|
await _pumpSheet(tester, repository: repository);
|
||||||
|
|
||||||
@@ -175,16 +175,19 @@ void main() {
|
|||||||
);
|
);
|
||||||
final interactions = FakeInteractionRepository()
|
final interactions = FakeInteractionRepository()
|
||||||
..nextLikeResult = const LikeToggleResult(liked: true, count: 7);
|
..nextLikeResult = const LikeToggleResult(liked: true, count: 7);
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
|
||||||
await _pumpSheet(
|
await _pumpSheet(
|
||||||
tester,
|
tester,
|
||||||
repository: repository,
|
repository: repository,
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
|
haptics: haptics,
|
||||||
);
|
);
|
||||||
await tester.tap(find.byKey(const Key('comment-like-10')));
|
await tester.tap(find.byKey(const Key('comment-like-10')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(interactions.likeTargets, ['COMMENT:10']);
|
expect(interactions.likeTargets, ['COMMENT:10']);
|
||||||
|
expect(haptics.lightImpacts, 1);
|
||||||
expect(find.text('7'), findsOneWidget);
|
expect(find.text('7'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -199,11 +202,13 @@ void main() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
final interactions = FakeInteractionRepository();
|
final interactions = FakeInteractionRepository();
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
|
||||||
await _pumpSheet(
|
await _pumpSheet(
|
||||||
tester,
|
tester,
|
||||||
repository: repository,
|
repository: repository,
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
|
haptics: haptics,
|
||||||
);
|
);
|
||||||
await tester.tap(find.byKey(const Key('comment-menu-10')));
|
await tester.tap(find.byKey(const Key('comment-menu-10')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -212,9 +217,13 @@ void main() {
|
|||||||
await tester.tap(find.byKey(const Key('report-submit')));
|
await tester.tap(find.byKey(const Key('report-submit')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(interactions.reports.single.targetType, InteractionTargetType.comment);
|
expect(
|
||||||
|
interactions.reports.single.targetType,
|
||||||
|
InteractionTargetType.comment,
|
||||||
|
);
|
||||||
expect(interactions.reports.single.targetId, '10');
|
expect(interactions.reports.single.targetId, '10');
|
||||||
expect(interactions.reports.single.reasonCode, 'SPAM');
|
expect(interactions.reports.single.reasonCode, 'SPAM');
|
||||||
|
expect(haptics.lightImpacts, 1);
|
||||||
expect(find.text('Report submitted. Thank you.'), findsOneWidget);
|
expect(find.text('Report submitted. Thank you.'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -281,11 +290,7 @@ void main() {
|
|||||||
pages: [
|
pages: [
|
||||||
CommentPage(
|
CommentPage(
|
||||||
comments: [
|
comments: [
|
||||||
commentFixture(
|
commentFixture(id: '10', content: 'My comment', mine: true),
|
||||||
id: '10',
|
|
||||||
content: 'My comment',
|
|
||||||
mine: true,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -315,6 +320,7 @@ Future<void> _pumpSheet(
|
|||||||
WidgetTester tester, {
|
WidgetTester tester, {
|
||||||
required FakeCommentRepository repository,
|
required FakeCommentRepository repository,
|
||||||
FakeInteractionRepository? interactions,
|
FakeInteractionRepository? interactions,
|
||||||
|
FakeHaptics? haptics,
|
||||||
}) async {
|
}) async {
|
||||||
final auth = await _auth();
|
final auth = await _auth();
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
@@ -325,6 +331,7 @@ Future<void> _pumpSheet(
|
|||||||
value: interactions ?? FakeInteractionRepository(),
|
value: interactions ?? FakeInteractionRepository(),
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider<AuthController>.value(value: auth),
|
ChangeNotifierProvider<AuthController>.value(value: auth),
|
||||||
|
Provider<Haptics>.value(value: haptics ?? FakeHaptics()),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
locale: const Locale('en'),
|
locale: const Locale('en'),
|
||||||
|
|||||||
@@ -45,4 +45,13 @@ void main() {
|
|||||||
expect(l10n.episodeProgress(2, 10), contains('2'));
|
expect(l10n.episodeProgress(2, 10), contains('2'));
|
||||||
expect(l10n.episodeProgress(2, 10), contains('10'));
|
expect(l10n.episodeProgress(2, 10), contains('10'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should_keep_auth_ui_copy_in_all_supported_locales', () async {
|
||||||
|
for (final locale in const [Locale('en'), Locale('zh'), Locale('id')]) {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(locale);
|
||||||
|
expect(l10n.authBrandTagline, isNotEmpty);
|
||||||
|
expect(l10n.showPassword, isNotEmpty);
|
||||||
|
expect(l10n.hidePassword, isNotEmpty);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('should_keep_haptic_calls_inside_platform_wrapper', () {
|
||||||
|
final violations = <String>[];
|
||||||
|
for (final entity in Directory('lib').listSync(recursive: true)) {
|
||||||
|
if (entity is! File || !entity.path.endsWith('.dart')) continue;
|
||||||
|
if (entity.path.endsWith('lib/core/platform/haptics.dart')) continue;
|
||||||
|
final lines = entity.readAsLinesSync();
|
||||||
|
for (var index = 0; index < lines.length; index++) {
|
||||||
|
if (lines[index].contains('HapticFeedback.')) {
|
||||||
|
violations.add('${entity.path}:${index + 1}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(violations, isEmpty, reason: violations.join('\n'));
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
test('should_ignore_platform_errors_when_haptics_are_unavailable', () async {
|
||||||
|
const channel = SystemChannels.platform;
|
||||||
|
final messenger =
|
||||||
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||||
|
messenger.setMockMethodCallHandler(channel, (_) async {
|
||||||
|
throw PlatformException(code: 'unavailable');
|
||||||
|
});
|
||||||
|
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
||||||
|
|
||||||
|
const haptics = FlutterHaptics();
|
||||||
|
await expectLater(haptics.selectionClick(), completes);
|
||||||
|
await expectLater(haptics.lightImpact(), completes);
|
||||||
|
await expectLater(haptics.mediumImpact(), completes);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import 'package:fruitshorts/core/data/repositories/download_repository.dart';
|
|||||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||||
import 'package:fruitshorts/core/data/services/download_controller.dart';
|
import 'package:fruitshorts/core/data/services/download_controller.dart';
|
||||||
|
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||||
import 'package:fruitshorts/pages/downloads/downloads_page.dart';
|
import 'package:fruitshorts/pages/downloads/downloads_page.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -17,20 +18,19 @@ import 'package:shared_preferences_platform_interface/in_memory_shared_preferenc
|
|||||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||||
|
|
||||||
import '../support/fake_http_adapter.dart';
|
import '../support/fake_http_adapter.dart';
|
||||||
|
import '../support/fake_haptics.dart';
|
||||||
|
|
||||||
DownloadPolicy _policy({
|
DownloadPolicy _policy({bool wifiOnly = true, String maxQuality = 'AUTO'}) =>
|
||||||
bool wifiOnly = true,
|
DownloadPolicy(
|
||||||
String maxQuality = 'AUTO',
|
maxPerDevice: 20,
|
||||||
}) => DownloadPolicy(
|
licenseDays: 30,
|
||||||
maxPerDevice: 20,
|
wifiOnly: wifiOnly,
|
||||||
licenseDays: 30,
|
maxQuality: maxQuality,
|
||||||
wifiOnly: wifiOnly,
|
maxStorageBytes: 0,
|
||||||
maxQuality: maxQuality,
|
used: 1,
|
||||||
maxStorageBytes: 0,
|
remaining: 19,
|
||||||
used: 1,
|
expirePolicyText: 'Licenses last 30 days',
|
||||||
remaining: 19,
|
);
|
||||||
expirePolicyText: 'Licenses last 30 days',
|
|
||||||
);
|
|
||||||
|
|
||||||
DownloadLicense _license(String episodeId) => DownloadLicense(
|
DownloadLicense _license(String episodeId) => DownloadLicense(
|
||||||
licenseId: 'license-$episodeId',
|
licenseId: 'license-$episodeId',
|
||||||
@@ -145,8 +145,14 @@ void main() {
|
|||||||
licenses: [_license('1')],
|
licenses: [_license('1')],
|
||||||
);
|
);
|
||||||
final controller = DownloadController(repository);
|
final controller = DownloadController(repository);
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
|
||||||
await _pumpPage(tester, auth: auth, controller: controller);
|
await _pumpPage(
|
||||||
|
tester,
|
||||||
|
auth: auth,
|
||||||
|
controller: controller,
|
||||||
|
haptics: haptics,
|
||||||
|
);
|
||||||
await tester.tap(find.byKey(const Key('download-clear')));
|
await tester.tap(find.byKey(const Key('download-clear')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(repository.clearCalls, 0);
|
expect(repository.clearCalls, 0);
|
||||||
@@ -155,23 +161,25 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(repository.clearCalls, 1);
|
expect(repository.clearCalls, 1);
|
||||||
|
expect(haptics.mediumImpacts, 1);
|
||||||
expect(find.byKey(const Key('downloads-empty')), findsOneWidget);
|
expect(find.byKey(const Key('downloads-empty')), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('should_render_unique_quality_options_when_policy_uses_a_preset', (
|
testWidgets(
|
||||||
tester,
|
'should_render_unique_quality_options_when_policy_uses_a_preset',
|
||||||
) async {
|
(tester) async {
|
||||||
final auth = await _auth(signedIn: true);
|
final auth = await _auth(signedIn: true);
|
||||||
final repository = FakeDownloadRepository(
|
final repository = FakeDownloadRepository(
|
||||||
policy: _policy(maxQuality: '720P'),
|
policy: _policy(maxQuality: '720P'),
|
||||||
);
|
);
|
||||||
final controller = DownloadController(repository);
|
final controller = DownloadController(repository);
|
||||||
|
|
||||||
await _pumpPage(tester, auth: auth, controller: controller);
|
await _pumpPage(tester, auth: auth, controller: controller);
|
||||||
|
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
expect(find.byKey(const Key('download-quality')), findsOneWidget);
|
expect(find.byKey(const Key('download-quality')), findsOneWidget);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<AuthController> _auth({required bool signedIn}) async {
|
Future<AuthController> _auth({required bool signedIn}) async {
|
||||||
@@ -198,12 +206,14 @@ Future<void> _pumpPage(
|
|||||||
WidgetTester tester, {
|
WidgetTester tester, {
|
||||||
required AuthController auth,
|
required AuthController auth,
|
||||||
required DownloadController controller,
|
required DownloadController controller,
|
||||||
|
FakeHaptics? haptics,
|
||||||
}) async {
|
}) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider<AuthController>.value(value: auth),
|
ChangeNotifierProvider<AuthController>.value(value: auth),
|
||||||
ChangeNotifierProvider<DownloadController>.value(value: controller),
|
ChangeNotifierProvider<DownloadController>.value(value: controller),
|
||||||
|
Provider<Haptics>.value(value: haptics ?? FakeHaptics()),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
locale: const Locale('en'),
|
locale: const Locale('en'),
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:fruitshorts/app.dart';
|
||||||
|
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||||
|
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||||
|
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||||
|
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||||
|
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||||
|
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||||
|
|
||||||
|
import '../support/fake_catalog.dart';
|
||||||
|
import '../support/fake_category.dart';
|
||||||
|
import '../support/fake_haptics.dart';
|
||||||
|
import '../support/fake_interaction_repositories.dart';
|
||||||
|
import '../support/widget_player.dart';
|
||||||
|
|
||||||
|
const _keys = [
|
||||||
|
Key('home-tabs-bar'),
|
||||||
|
Key('tab-discover'),
|
||||||
|
Key('tab-home'),
|
||||||
|
Key('tab-my-list'),
|
||||||
|
Key('tab-my'),
|
||||||
|
];
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
setUp(() {
|
||||||
|
SharedPreferencesAsyncPlatform.instance =
|
||||||
|
InMemorySharedPreferencesAsync.withData({
|
||||||
|
'auth.accessToken': 'test-access',
|
||||||
|
'auth.refreshToken': 'test-refresh',
|
||||||
|
'auth.user': '{"uid":"9","nickname":"Viewer","avatarUrl":""}',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should_theme_four_tabs_and_switch_selected_state_when_tapped', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
await _pumpApp(tester, haptics);
|
||||||
|
haptics.reset();
|
||||||
|
|
||||||
|
for (final key in _keys) {
|
||||||
|
expect(find.byKey(key), findsOneWidget);
|
||||||
|
}
|
||||||
|
for (final key in _keys.skip(1)) {
|
||||||
|
expect(tester.getSize(find.byKey(key)).height, greaterThanOrEqualTo(48));
|
||||||
|
}
|
||||||
|
|
||||||
|
final barFinder = find.byKey(const Key('home-tabs-bar'));
|
||||||
|
final bar = tester.widget<Container>(barFinder);
|
||||||
|
final decoration = bar.decoration as BoxDecoration;
|
||||||
|
final border = decoration.border as Border;
|
||||||
|
final context = tester.element(barFinder);
|
||||||
|
expect(decoration.color, AppColors.bar);
|
||||||
|
expect(border.top.color, Theme.of(context).colorScheme.outlineVariant);
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<AnimatedContainer>(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(const Key('tab-home')),
|
||||||
|
matching: find.byType(AnimatedContainer),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.duration,
|
||||||
|
lessThanOrEqualTo(const Duration(milliseconds: 200)),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(const Key('tab-home')),
|
||||||
|
matching: find.byIcon(Icons.movie_rounded),
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.byKey(const Key('tab-discover')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(haptics.selectionClicks, 1);
|
||||||
|
await tester.tap(find.byKey(const Key('tab-discover')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(haptics.selectionClicks, 1);
|
||||||
|
expect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(const Key('tab-discover')),
|
||||||
|
matching: find.byIcon(Icons.home_rounded),
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byKey(const Key('tab-home')),
|
||||||
|
matching: find.byIcon(Icons.movie_outlined),
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should_hide_themed_navigation_when_immersive_mode_is_enabled', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await _pumpApp(tester);
|
||||||
|
await tester.tap(find.byTooltip('Clear screen'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
for (final key in _keys) {
|
||||||
|
expect(find.byKey(key), findsNothing);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should_not_haptic_when_ordinary_list_item_is_opened', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
await _pumpApp(tester, haptics);
|
||||||
|
await tester.tap(find.byKey(const Key('tab-my')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
haptics.reset();
|
||||||
|
|
||||||
|
await tester.tap(find.text('App Language'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(haptics.calls, isEmpty);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _pumpApp(WidgetTester tester, [FakeHaptics? haptics]) async {
|
||||||
|
tester.view.physicalSize = const Size(390, 844);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
final catalog = FakeCatalogRepository();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
LumaDramaApp(
|
||||||
|
playerFactory: createWidgetPlayer,
|
||||||
|
catalogRepository: catalog,
|
||||||
|
categoryRepository: FakeCategoryRepository(catalog: catalog),
|
||||||
|
watchHistoryRepository: InMemoryWatchHistoryRepository(),
|
||||||
|
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
|
||||||
|
playbackRepository: FakePlaybackRepository(),
|
||||||
|
commentRepository: FakeCommentRepository(),
|
||||||
|
interactionRepository: FakeInteractionRepository(),
|
||||||
|
haptics: haptics ?? FakeHaptics(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.byKey(const Key('tab-home')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
|||||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||||
import 'package:fruitshorts/core/data/services/favorite_controller.dart';
|
import 'package:fruitshorts/core/data/services/favorite_controller.dart';
|
||||||
|
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||||
import 'package:fruitshorts/pages/favorites/favorites_page.dart';
|
import 'package:fruitshorts/pages/favorites/favorites_page.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -16,6 +17,7 @@ import 'package:shared_preferences_platform_interface/in_memory_shared_preferenc
|
|||||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||||
|
|
||||||
import '../support/fake_http_adapter.dart';
|
import '../support/fake_http_adapter.dart';
|
||||||
|
import '../support/fake_haptics.dart';
|
||||||
|
|
||||||
Drama _card(String id) => Drama(
|
Drama _card(String id) => Drama(
|
||||||
id: id,
|
id: id,
|
||||||
@@ -58,11 +60,13 @@ void main() {
|
|||||||
cards: [_card('signal')],
|
cards: [_card('signal')],
|
||||||
)..failRemove = true;
|
)..failRemove = true;
|
||||||
final favorites = FavoriteController(repository);
|
final favorites = FavoriteController(repository);
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
|
||||||
await _pumpPage(tester, auth: auth, favorites: favorites);
|
await _pumpPage(tester, auth: auth, favorites: favorites, haptics: haptics);
|
||||||
await tester.tap(find.byKey(const Key('favorite-remove-signal')));
|
await tester.tap(find.byKey(const Key('favorite-remove-signal')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(haptics.lightImpacts, 1);
|
||||||
expect(find.text('Drama signal'), findsOneWidget);
|
expect(find.text('Drama signal'), findsOneWidget);
|
||||||
expect(
|
expect(
|
||||||
find.text('Could not update favorites. Please retry.'),
|
find.text('Could not update favorites. Please retry.'),
|
||||||
@@ -134,12 +138,14 @@ Future<void> _pumpPage(
|
|||||||
WidgetTester tester, {
|
WidgetTester tester, {
|
||||||
required AuthController auth,
|
required AuthController auth,
|
||||||
required FavoriteController favorites,
|
required FavoriteController favorites,
|
||||||
|
FakeHaptics? haptics,
|
||||||
}) async {
|
}) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider<AuthController>.value(value: auth),
|
ChangeNotifierProvider<AuthController>.value(value: auth),
|
||||||
ChangeNotifierProvider<FavoriteController>.value(value: favorites),
|
ChangeNotifierProvider<FavoriteController>.value(value: favorites),
|
||||||
|
Provider<Haptics>.value(value: haptics ?? FakeHaptics()),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
locale: const Locale('en'),
|
locale: const Locale('en'),
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
|
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||||
|
|
||||||
|
/// Deterministic haptics recorder for widget tests.
|
||||||
|
class FakeHaptics implements Haptics {
|
||||||
|
final List<String> calls = [];
|
||||||
|
int selectionClicks = 0;
|
||||||
|
int lightImpacts = 0;
|
||||||
|
int mediumImpacts = 0;
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
calls.clear();
|
||||||
|
selectionClicks = 0;
|
||||||
|
lightImpacts = 0;
|
||||||
|
mediumImpacts = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> selectionClick() async {
|
||||||
|
calls.add('selection');
|
||||||
|
selectionClicks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> lightImpact() async {
|
||||||
|
calls.add('light');
|
||||||
|
lightImpacts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> mediumImpact() async {
|
||||||
|
calls.add('medium');
|
||||||
|
mediumImpacts++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
|
|||||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||||
|
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||||
import 'package:fruitshorts/pages/watch_records/watch_records_page.dart';
|
import 'package:fruitshorts/pages/watch_records/watch_records_page.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -19,6 +20,7 @@ import 'package:shared_preferences_platform_interface/shared_preferences_async_p
|
|||||||
|
|
||||||
import '../support/fake_catalog.dart';
|
import '../support/fake_catalog.dart';
|
||||||
import '../support/fake_http_adapter.dart';
|
import '../support/fake_http_adapter.dart';
|
||||||
|
import '../support/fake_haptics.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
setUp(() {
|
setUp(() {
|
||||||
@@ -101,12 +103,14 @@ void main() {
|
|||||||
(tester) async {
|
(tester) async {
|
||||||
final auth = await _auth(signedIn: true);
|
final auth = await _auth(signedIn: true);
|
||||||
final history = CountingWatchHistory([_progress('the-signal-demo')]);
|
final history = CountingWatchHistory([_progress('the-signal-demo')]);
|
||||||
|
final haptics = FakeHaptics();
|
||||||
|
|
||||||
await _pumpPage(
|
await _pumpPage(
|
||||||
tester,
|
tester,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
history: history,
|
history: history,
|
||||||
catalog: FakeCatalogRepository(),
|
catalog: FakeCatalogRepository(),
|
||||||
|
haptics: haptics,
|
||||||
);
|
);
|
||||||
await tester.tap(find.byKey(const Key('watch-records-clear')));
|
await tester.tap(find.byKey(const Key('watch-records-clear')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -118,6 +122,7 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(history.clearCalls, 1);
|
expect(history.clearCalls, 1);
|
||||||
|
expect(haptics.mediumImpacts, 1);
|
||||||
expect(find.text('No watch history yet.'), findsOneWidget);
|
expect(find.text('No watch history yet.'), findsOneWidget);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -156,6 +161,7 @@ Future<void> _pumpPage(
|
|||||||
required AuthController auth,
|
required AuthController auth,
|
||||||
required WatchHistoryRepository history,
|
required WatchHistoryRepository history,
|
||||||
required CatalogRepository catalog,
|
required CatalogRepository catalog,
|
||||||
|
FakeHaptics? haptics,
|
||||||
}) async {
|
}) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
@@ -163,6 +169,7 @@ Future<void> _pumpPage(
|
|||||||
ChangeNotifierProvider<AuthController>.value(value: auth),
|
ChangeNotifierProvider<AuthController>.value(value: auth),
|
||||||
Provider<WatchHistoryRepository>.value(value: history),
|
Provider<WatchHistoryRepository>.value(value: history),
|
||||||
Provider<CatalogRepository>.value(value: catalog),
|
Provider<CatalogRepository>.value(value: catalog),
|
||||||
|
Provider<Haptics>.value(value: haptics ?? FakeHaptics()),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
locale: const Locale('en'),
|
locale: const Locale('en'),
|
||||||
|
|||||||
Reference in new issue
Block a user