feat(app): 完成 P0 钱包解锁、下载落盘与手机号登录
This commit is contained in:
1 parent
de941c841c
commit
136ee74618
47 files changed
+3264
-70
No files matched your search
@@ -13,6 +13,7 @@ import '../../core/theme/app_dimens.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import 'auth_logic.dart';
|
||||
import 'phone_auth_sheet.dart';
|
||||
|
||||
part 'auth_widgets.dart';
|
||||
part 'auth_form_widgets.dart';
|
||||
@@ -334,22 +335,13 @@ class _AuthPageState extends State<AuthPage> {
|
||||
style: const TextStyle(color: Color(0xFF9A96A3), fontSize: 11),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_AuthEntryButton(
|
||||
key: const Key('auth-entry-google'),
|
||||
label: 'G ${l10n.authContinueGoogle}',
|
||||
background: Colors.white,
|
||||
foreground: const Color(0xFF1A1A1A),
|
||||
leadingColor: const Color(0xFF4285F4),
|
||||
onTap: () => _comingSoon(l10n),
|
||||
),
|
||||
const SizedBox(height: 11),
|
||||
_AuthEntryButton(
|
||||
key: const Key('auth-entry-phone'),
|
||||
label: l10n.authPhoneSignIn,
|
||||
icon: Icons.phone_android_rounded,
|
||||
background: AppColors.input,
|
||||
foreground: AppColors.onSurface,
|
||||
onTap: () => _comingSoon(l10n),
|
||||
onTap: _openPhoneSheet,
|
||||
),
|
||||
const SizedBox(height: 11),
|
||||
_AuthEntryButton(
|
||||
@@ -374,10 +366,12 @@ class _AuthPageState extends State<AuthPage> {
|
||||
],
|
||||
);
|
||||
|
||||
void _comingSoon(AppLocalizations l10n) {
|
||||
ScaffoldMessenger.of(
|
||||
Future<void> _openPhoneSheet() async {
|
||||
final signedIn = await showPhoneAuthSheet(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(l10n.comingSoon)));
|
||||
signUp: _logic.signUpMode,
|
||||
);
|
||||
if (signedIn == true && mounted) Navigator.of(context).maybePop();
|
||||
}
|
||||
|
||||
Widget _authCard(AppLocalizations l10n) => _AuthCard(
|
||||
@@ -427,7 +421,6 @@ class _AuthEntryButton extends StatelessWidget {
|
||||
required this.foreground,
|
||||
required this.onTap,
|
||||
this.icon,
|
||||
this.leadingColor,
|
||||
});
|
||||
|
||||
final String label;
|
||||
@@ -435,7 +428,6 @@ class _AuthEntryButton extends StatelessWidget {
|
||||
final Color foreground;
|
||||
final VoidCallback onTap;
|
||||
final IconData? icon;
|
||||
final Color? leadingColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -451,7 +443,7 @@ class _AuthEntryButton extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (icon != null)
|
||||
Icon(icon, size: 16, color: leadingColor ?? foreground),
|
||||
Icon(icon, size: 16, color: foreground),
|
||||
if (icon != null) const SizedBox(width: 7),
|
||||
Flexible(
|
||||
child: Text(
|
||||
|
||||
@@ -0,0 +1,358 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/remote/api_client.dart';
|
||||
import '../../core/data/services/auth_controller.dart';
|
||||
import '../../core/platform/haptics.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
const double _fieldHeight = 52;
|
||||
const double _fieldRadius = 14;
|
||||
const double _sheetRadius = 28;
|
||||
const double _buttonHeight = 52;
|
||||
const int _resendSeconds = 60;
|
||||
const int _phoneMinLength = 8;
|
||||
const int _codeMinLength = 4;
|
||||
|
||||
/// 打开手机号 OTP 登录/注册表单;成功登录后返回 true。
|
||||
Future<bool?> showPhoneAuthSheet(BuildContext context, {bool signUp = false}) {
|
||||
return showModalBottomSheet<bool>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
barrierColor: Colors.black.withValues(alpha: 0.62),
|
||||
builder: (_) => PhoneAuthSheet(initialSignUp: signUp),
|
||||
);
|
||||
}
|
||||
|
||||
class PhoneAuthSheet extends StatefulWidget {
|
||||
const PhoneAuthSheet({super.key, this.initialSignUp = false});
|
||||
|
||||
final bool initialSignUp;
|
||||
|
||||
@override
|
||||
State<PhoneAuthSheet> createState() => _PhoneAuthSheetState();
|
||||
}
|
||||
|
||||
class _PhoneAuthSheetState extends State<PhoneAuthSheet> {
|
||||
late final TextEditingController _phone;
|
||||
late final TextEditingController _code;
|
||||
late final FocusNode _phoneFocus;
|
||||
late final FocusNode _codeFocus;
|
||||
Timer? _countdown;
|
||||
bool _signUp = false;
|
||||
bool _sending = false;
|
||||
bool _submitting = false;
|
||||
int _remaining = 0;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_signUp = widget.initialSignUp;
|
||||
_phone = TextEditingController();
|
||||
_code = TextEditingController();
|
||||
_phoneFocus = FocusNode(debugLabel: 'phone-auth-number');
|
||||
_codeFocus = FocusNode(debugLabel: 'phone-auth-code');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_countdown?.cancel();
|
||||
_phone.dispose();
|
||||
_code.dispose();
|
||||
_phoneFocus.dispose();
|
||||
_codeFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String get _target => _phone.text.replaceAll(RegExp(r'[\s-]'), '');
|
||||
|
||||
bool get _phoneValid => _target.length >= _phoneMinLength;
|
||||
|
||||
Future<void> _sendCode() async {
|
||||
if (_sending || _remaining > 0) return;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
if (!_phoneValid) {
|
||||
setState(() => _error = l10n.authPhoneInvalid);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_sending = true;
|
||||
_error = null;
|
||||
});
|
||||
final haptics = context.read<Haptics>();
|
||||
final auth = context.read<AuthController>();
|
||||
await haptics.lightImpact();
|
||||
try {
|
||||
await auth.sendOtp(
|
||||
target: _target,
|
||||
scene: _signUp ? 'REGISTER' : 'LOGIN',
|
||||
);
|
||||
if (!mounted) return;
|
||||
_startCountdown();
|
||||
setState(() => _error = null);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(l10n.authCodeSent)));
|
||||
_codeFocus.requestFocus();
|
||||
} on ApiException catch (error) {
|
||||
if (mounted) setState(() => _error = error.message);
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _error = l10n.authNetworkError);
|
||||
} finally {
|
||||
if (mounted) setState(() => _sending = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _startCountdown() {
|
||||
_countdown?.cancel();
|
||||
_remaining = _resendSeconds;
|
||||
_countdown = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (!mounted) return timer.cancel();
|
||||
setState(() => _remaining--);
|
||||
if (_remaining <= 0) timer.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (_submitting) return;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
if (!_phoneValid) {
|
||||
setState(() => _error = l10n.authPhoneInvalid);
|
||||
return;
|
||||
}
|
||||
if (_code.text.trim().length < _codeMinLength) {
|
||||
setState(() => _error = l10n.authCodeRequired);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_submitting = true;
|
||||
_error = null;
|
||||
});
|
||||
final haptics = context.read<Haptics>();
|
||||
final auth = context.read<AuthController>();
|
||||
await haptics.lightImpact();
|
||||
try {
|
||||
if (_signUp) {
|
||||
await auth.registerWithPhone(target: _target, code: _code.text.trim());
|
||||
} else {
|
||||
await auth.signInWithPhone(target: _target, code: _code.text.trim());
|
||||
}
|
||||
if (mounted) Navigator.of(context).pop(true);
|
||||
} on ApiException catch (error) {
|
||||
if (mounted) setState(() => _error = error.message);
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _error = l10n.authNetworkError);
|
||||
} finally {
|
||||
if (mounted) setState(() => _submitting = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _switchMode() {
|
||||
setState(() {
|
||||
_signUp = !_signUp;
|
||||
_error = null;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final bottom = MediaQuery.viewInsetsOf(context).bottom;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: bottom),
|
||||
child: Container(
|
||||
key: const Key('phone-auth-sheet'),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.card,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(_sheetRadius)),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(22, 10, 22, 26),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(child: _grabber()),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_signUp ? l10n.authPhoneSignUp : l10n.authPhoneTitle,
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
l10n.authSubtitle,
|
||||
style: const TextStyle(color: AppColors.subtle, fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_phoneField(l10n),
|
||||
const SizedBox(height: 12),
|
||||
_codeField(l10n),
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
_error!,
|
||||
key: const Key('auth-phone-error'),
|
||||
style: const TextStyle(color: AppColors.accent, fontSize: 12),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 18),
|
||||
_submitButton(l10n),
|
||||
const SizedBox(height: 8),
|
||||
Center(
|
||||
child: TextButton(
|
||||
key: const Key('auth-phone-switch'),
|
||||
onPressed: _submitting ? null : _switchMode,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.blueSoft,
|
||||
minimumSize: const Size(48, 48),
|
||||
),
|
||||
child: Text(
|
||||
_signUp ? l10n.authSwitchToSignIn : l10n.authSwitchToSignUp,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _grabber() => Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.subtle.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _phoneField(AppLocalizations l10n) => SizedBox(
|
||||
height: _fieldHeight,
|
||||
child: TextField(
|
||||
key: const Key('auth-phone-number'),
|
||||
controller: _phone,
|
||||
focusNode: _phoneFocus,
|
||||
enabled: !_submitting,
|
||||
keyboardType: TextInputType.phone,
|
||||
textInputAction: TextInputAction.next,
|
||||
autofillHints: const [AutofillHints.telephoneNumber],
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r'[0-9+\s-]')),
|
||||
LengthLimitingTextInputFormatter(20),
|
||||
],
|
||||
onSubmitted: (_) => _codeFocus.requestFocus(),
|
||||
onChanged: (_) => setState(() => _error = null),
|
||||
style: const TextStyle(color: AppColors.onSurface, fontSize: 15),
|
||||
decoration: _decoration(l10n.authPhoneLabel, l10n.authPhoneHint),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _codeField(AppLocalizations l10n) => SizedBox(
|
||||
height: _fieldHeight,
|
||||
child: TextField(
|
||||
key: const Key('auth-phone-code'),
|
||||
controller: _code,
|
||||
focusNode: _codeFocus,
|
||||
enabled: !_submitting,
|
||||
keyboardType: TextInputType.number,
|
||||
textInputAction: TextInputAction.done,
|
||||
autofillHints: const [AutofillHints.oneTimeCode],
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
LengthLimitingTextInputFormatter(6),
|
||||
],
|
||||
onSubmitted: (_) => _submit(),
|
||||
onChanged: (_) => setState(() => _error = null),
|
||||
style: const TextStyle(color: AppColors.onSurface, fontSize: 15),
|
||||
decoration: _decoration(l10n.authCodeLabel, l10n.authCodeHint).copyWith(
|
||||
suffixIcon: _sendButton(l10n),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _sendButton(AppLocalizations l10n) => Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: TextButton(
|
||||
key: const Key('auth-send-code'),
|
||||
onPressed: _sending || _remaining > 0 ? null : _sendCode,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.blueSoft,
|
||||
minimumSize: const Size(48, 48),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
),
|
||||
child: _sending
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(
|
||||
_remaining > 0
|
||||
? l10n.authResendCode(_remaining)
|
||||
: l10n.authSendCode,
|
||||
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _submitButton(AppLocalizations l10n) => SizedBox(
|
||||
width: double.infinity,
|
||||
height: _buttonHeight,
|
||||
child: FilledButton(
|
||||
key: const Key('auth-phone-submit'),
|
||||
onPressed: _submitting ? null : _submit,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.blue,
|
||||
foregroundColor: AppColors.onPrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(_buttonHeight / 2),
|
||||
),
|
||||
),
|
||||
child: _submitting
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: AppColors.onPrimary,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
_signUp ? l10n.authPhoneSignUpAction : l10n.authPhoneSignInAction,
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w800),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
InputDecoration _decoration(String label, String hint) => InputDecoration(
|
||||
labelText: label,
|
||||
hintText: hint,
|
||||
labelStyle: const TextStyle(color: AppColors.subtle),
|
||||
hintStyle: const TextStyle(color: AppColors.subtle),
|
||||
filled: true,
|
||||
fillColor: AppColors.input,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(_fieldRadius),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(_fieldRadius),
|
||||
borderSide: const BorderSide(color: AppColors.blue, width: 1.5),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/models/download_license.dart';
|
||||
import '../../core/data/models/download_policy.dart';
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/services/auth_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/formatting/error_text.dart';
|
||||
@@ -18,6 +19,7 @@ import '../../core/theme/app_theme.dart';
|
||||
import '../../core/widgets/auth_gate.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../player/player_view.dart';
|
||||
import 'downloads_binding.dart';
|
||||
|
||||
/// 下载授权与状态管理页;本批不落盘,只管理服务端授权。
|
||||
@@ -135,7 +137,12 @@ class _DownloadsBody extends StatelessWidget {
|
||||
for (final license in downloads.licenses) ...[
|
||||
_LicenseTile(
|
||||
license: license,
|
||||
downloads: downloads,
|
||||
onRemove: () => _remove(context, license.episodeId),
|
||||
onPlay: () => _playOffline(context, license),
|
||||
onDownload: () => unawaited(
|
||||
downloads.startDownload(license.episodeId, license: license),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
@@ -144,6 +151,32 @@ class _DownloadsBody extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _playOffline(BuildContext context, DownloadLicense license) {
|
||||
final drama = Drama(
|
||||
id: license.dramaId,
|
||||
title: license.dramaTitle,
|
||||
synopsis: '',
|
||||
posterUrl: '',
|
||||
episodes: [
|
||||
Episode(
|
||||
id: license.episodeId,
|
||||
number: license.episodeNo,
|
||||
title: 'Episode ${license.episodeNo}',
|
||||
isFree: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => PlayerPage(
|
||||
drama: drama,
|
||||
initialIndex: 0,
|
||||
downloads: downloads,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _remove(BuildContext context, String episodeId) async {
|
||||
unawaited(context.read<Haptics>().mediumImpact());
|
||||
final ok = await downloads.remove(episodeId);
|
||||
@@ -302,14 +335,35 @@ class _PolicyPanel extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _LicenseTile extends StatelessWidget {
|
||||
const _LicenseTile({required this.license, required this.onRemove});
|
||||
const _LicenseTile({
|
||||
required this.license,
|
||||
required this.downloads,
|
||||
required this.onRemove,
|
||||
required this.onPlay,
|
||||
required this.onDownload,
|
||||
});
|
||||
|
||||
final DownloadLicense license;
|
||||
final DownloadController downloads;
|
||||
final VoidCallback onRemove;
|
||||
final VoidCallback onPlay;
|
||||
final VoidCallback onDownload;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final downloaded = downloads.isDownloaded(license.episodeId);
|
||||
final downloading = downloads.isDownloading(license.episodeId);
|
||||
final progress = downloaded
|
||||
? 1.0
|
||||
: downloading
|
||||
? downloads.progressFor(license.episodeId)
|
||||
: license.progressPercent / 100;
|
||||
final taskStatus = downloaded
|
||||
? 'COMPLETED'
|
||||
: downloading
|
||||
? 'DOWNLOADING'
|
||||
: license.taskStatus;
|
||||
return Container(
|
||||
key: ValueKey('download-license-${license.episodeId}'),
|
||||
padding: const EdgeInsets.all(12),
|
||||
@@ -335,6 +389,20 @@ class _LicenseTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(l10n.episodeLabel(license.episodeNo)),
|
||||
if (downloaded)
|
||||
IconButton(
|
||||
key: ValueKey('download-play-${license.episodeId}'),
|
||||
tooltip: l10n.play,
|
||||
onPressed: onPlay,
|
||||
icon: const Icon(Icons.play_circle_outline_rounded),
|
||||
)
|
||||
else if (!downloading)
|
||||
IconButton(
|
||||
key: ValueKey('download-start-${license.episodeId}'),
|
||||
tooltip: l10n.downloads,
|
||||
onPressed: onDownload,
|
||||
icon: const Icon(Icons.download_rounded),
|
||||
),
|
||||
IconButton(
|
||||
key: ValueKey('download-remove-${license.episodeId}'),
|
||||
tooltip: l10n.remove,
|
||||
@@ -352,7 +420,7 @@ class _LicenseTile extends StatelessWidget {
|
||||
style: const TextStyle(color: AppColors.blueSoft, fontSize: 12),
|
||||
),
|
||||
Text(
|
||||
l10n.downloadTaskStatus(license.taskStatus),
|
||||
l10n.downloadTaskStatus(taskStatus),
|
||||
style: const TextStyle(color: AppColors.muted, fontSize: 12),
|
||||
),
|
||||
Text(
|
||||
@@ -371,7 +439,7 @@ class _LicenseTile extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(AppDimens.progressRadius),
|
||||
child: LinearProgressIndicator(
|
||||
minHeight: AppDimens.progressHeight,
|
||||
value: (license.progressPercent / 100).clamp(0.0, 1.0),
|
||||
value: progress.clamp(0.0, 1.0),
|
||||
backgroundColor: Colors.white24,
|
||||
valueColor: const AlwaysStoppedAnimation(AppColors.blueSoft),
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/models/watch_progress.dart';
|
||||
@@ -9,6 +10,8 @@ import '../../core/data/remote/api_client.dart';
|
||||
import '../../core/data/repositories/watch_history_repository.dart';
|
||||
import '../../core/data/repositories/playback_repository.dart';
|
||||
import '../../core/data/services/favorite_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../player/player_view.dart';
|
||||
|
||||
class DramaDetailLogic extends ChangeNotifier {
|
||||
@@ -104,7 +107,12 @@ class DramaDetailLogic extends ChangeNotifier {
|
||||
Future<void> openPlayer(BuildContext context, int index) async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => PlayerPage(drama: drama, initialIndex: index),
|
||||
builder: (_) => PlayerPage(
|
||||
drama: drama,
|
||||
initialIndex: index,
|
||||
wallet: context.read<WalletController>(),
|
||||
downloads: context.read<DownloadController>(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await loadContinue();
|
||||
|
||||
@@ -5,6 +5,8 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../discover/discover_logic.dart';
|
||||
import '../drama_detail/drama_detail_view.dart';
|
||||
import '../mine/mine_logic.dart';
|
||||
@@ -94,7 +96,12 @@ class HomeLogic extends ChangeNotifier {
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => PlayerPage(drama: playable, initialIndex: 0),
|
||||
builder: (_) => PlayerPage(
|
||||
drama: playable,
|
||||
initialIndex: 0,
|
||||
wallet: context.read<WalletController>(),
|
||||
downloads: context.read<DownloadController>(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import '../../core/config/app_config.dart';
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/services/auth_controller.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/platform/haptics.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
@@ -200,6 +202,8 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
onSearch: () => logic.select(1, search: true),
|
||||
onMenu: () => _openMenu(context),
|
||||
onImmersiveChanged: logic.onImmersiveChanged,
|
||||
wallet: context.read<WalletController>(),
|
||||
downloads: context.read<DownloadController>(),
|
||||
),
|
||||
DiscoverPage(
|
||||
drama: logic.currentDrama,
|
||||
@@ -229,6 +233,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
signedIn: signedIn,
|
||||
onSignIn: () => openAuthPage(context),
|
||||
onSignOut: () => context.read<AuthController>().signOut(),
|
||||
wallet: context.read<WalletController>(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -13,6 +13,7 @@ import '../../core/data/repositories/watch_history_repository.dart';
|
||||
import '../../core/data/services/auth_controller.dart';
|
||||
import '../../core/data/services/favorite_controller.dart';
|
||||
import '../../core/data/services/interaction_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/formatting/error_text.dart';
|
||||
import '../../core/formatting/localized_content.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
@@ -25,6 +26,7 @@ import '../account/account_entry_card.dart';
|
||||
import '../downloads/downloads_page.dart';
|
||||
import '../favorites/favorites_page.dart';
|
||||
import '../notices/notices_page.dart';
|
||||
import '../wallet/wallet_page.dart';
|
||||
import '../watch_records/watch_records_page.dart';
|
||||
import 'mine_binding.dart';
|
||||
import 'mine_logic.dart';
|
||||
@@ -46,6 +48,7 @@ class MyPage extends StatefulWidget {
|
||||
this.onSignOut,
|
||||
this.dramas,
|
||||
this.onDramaSelected,
|
||||
this.wallet,
|
||||
this.debugShowSetting = kDebugMode,
|
||||
});
|
||||
|
||||
@@ -63,6 +66,7 @@ class MyPage extends StatefulWidget {
|
||||
final VoidCallback? onSignOut;
|
||||
final List<Drama>? dramas;
|
||||
final ValueChanged<Drama>? onDramaSelected;
|
||||
final WalletController? wallet;
|
||||
final bool debugShowSetting;
|
||||
|
||||
@override
|
||||
@@ -308,9 +312,21 @@ class _MyPageState extends State<MyPage> {
|
||||
}
|
||||
|
||||
Widget _wallet(AppLocalizations l10n) {
|
||||
final wallet = widget.wallet;
|
||||
if (wallet == null) return _walletCard(l10n, null);
|
||||
return ListenableBuilder(
|
||||
listenable: wallet,
|
||||
builder: (context, _) => _walletCard(l10n, wallet),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _walletCard(AppLocalizations l10n, WalletController? wallet) {
|
||||
final value = wallet == null
|
||||
? l10n.coins
|
||||
: l10n.walletBalanceShort(wallet.balance);
|
||||
return InkWell(
|
||||
key: const Key('mine-wallet'),
|
||||
onTap: () => _mockSnack(l10n),
|
||||
onTap: () => _openWallet(context),
|
||||
borderRadius: BorderRadius.circular(13),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
@@ -340,7 +356,7 @@ class _MyPageState extends State<MyPage> {
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'0 ${l10n.coins} · ${l10n.topUpWallet}',
|
||||
widget.signedIn ? value : l10n.logInHint,
|
||||
style: const TextStyle(
|
||||
color: AppColors.accent,
|
||||
fontSize: 9,
|
||||
@@ -360,6 +376,16 @@ class _MyPageState extends State<MyPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _openWallet(BuildContext context) {
|
||||
if (!widget.signedIn) {
|
||||
widget.onSignIn?.call();
|
||||
return;
|
||||
}
|
||||
Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => const WalletPage()));
|
||||
}
|
||||
|
||||
WatchProgress? get _continueRecord {
|
||||
for (final record in logic.recent) {
|
||||
if (!record.finished && record.hasPosition) return record;
|
||||
@@ -934,12 +960,6 @@ class _MyPageState extends State<MyPage> {
|
||||
}
|
||||
}
|
||||
|
||||
void _mockSnack(AppLocalizations l10n) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(l10n.mockNotice)));
|
||||
}
|
||||
|
||||
Widget _poster(
|
||||
Drama drama, {
|
||||
required double width,
|
||||
|
||||
@@ -3,15 +3,21 @@
|
||||
import '../../core/data/repositories/watch_history_repository.dart';
|
||||
import '../../core/data/repositories/playback_repository.dart';
|
||||
import '../../core/data/services/android_picture_in_picture.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import 'player_logic.dart';
|
||||
|
||||
class PlayerBinding {
|
||||
PlayerLogic create({
|
||||
required WatchHistoryRepository history,
|
||||
required PlaybackRepository playback,
|
||||
WalletController? wallet,
|
||||
DownloadController? downloads,
|
||||
}) => PlayerLogic(
|
||||
history: history,
|
||||
playback: playback,
|
||||
pictureInPicture: AndroidPictureInPicture(),
|
||||
wallet: wallet,
|
||||
downloads: downloads,
|
||||
);
|
||||
}
|
||||
@@ -14,10 +14,12 @@ import '../../core/data/repositories/playback_repository.dart';
|
||||
import '../../core/data/repositories/watch_history_repository.dart';
|
||||
import '../../core/data/services/android_picture_in_picture.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/platform_share_service.dart';
|
||||
import '../../core/data/services/playback_queue.dart';
|
||||
import '../../core/data/services/playback_session.dart';
|
||||
import '../../core/data/services/video_player_port.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/formatting/localized_content.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
@@ -37,11 +39,15 @@ class PlayerLogic extends ChangeNotifier {
|
||||
required this.history,
|
||||
required this.playback,
|
||||
required this.pictureInPicture,
|
||||
this.wallet,
|
||||
this.downloads,
|
||||
});
|
||||
|
||||
final WatchHistoryRepository history;
|
||||
final PlaybackRepository playback;
|
||||
final AndroidPictureInPicture pictureInPicture;
|
||||
final WalletController? wallet;
|
||||
final DownloadController? downloads;
|
||||
|
||||
late PageController pages;
|
||||
late PlaybackQueue queue;
|
||||
@@ -75,6 +81,10 @@ class PlayerLogic extends ChangeNotifier {
|
||||
bool pipPreparing = false;
|
||||
final Map<String, int> pickedEpisode = {};
|
||||
|
||||
/// 解锁中的集 id 与失败文案;空表示没有进行中的解锁。
|
||||
String? unlockingEpisodeId;
|
||||
String? unlockError;
|
||||
|
||||
bool Function() isMounted = () => false;
|
||||
bool homeMode = false;
|
||||
bool embedded = false;
|
||||
@@ -194,7 +204,7 @@ class PlayerLogic extends ChangeNotifier {
|
||||
|
||||
/// 票据门:起播前先拿票(命中未过期缓存就不会重复请求),
|
||||
/// 拿不到地址就交给 [blockedTicket] 让 UI 提示解锁/暂无片源。
|
||||
Future<bool> ensureTicket(int index) async {
|
||||
Future<bool> ensureTicket(int index, {bool forceRefresh = false}) async {
|
||||
if (index < 0 || index >= sessionEpisodes.length) return false;
|
||||
final episode = sessionEpisodes[index];
|
||||
final request = pageRequest;
|
||||
@@ -202,7 +212,18 @@ class PlayerLogic extends ChangeNotifier {
|
||||
ticketError = null;
|
||||
notify();
|
||||
try {
|
||||
final ticket = await playback.ticketFor(episode.id);
|
||||
final localPath = await downloads?.findLocalPath(episode.id);
|
||||
if (request != pageRequest) return false;
|
||||
if (localPath != null) {
|
||||
blockedTicket = null;
|
||||
blockedEpisodeId = null;
|
||||
sessionEpisodes[index] = episode.withVideoUrl(_fileUrl(localPath));
|
||||
return true;
|
||||
}
|
||||
final ticket = await playback.ticketFor(
|
||||
episode.id,
|
||||
forceRefresh: forceRefresh,
|
||||
);
|
||||
if (request != pageRequest) return false;
|
||||
blockedTicket = null;
|
||||
blockedEpisodeId = null;
|
||||
@@ -231,6 +252,9 @@ class PlayerLogic extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
String _fileUrl(String path) =>
|
||||
path.startsWith('file:') ? path : Uri.file(path).toString();
|
||||
|
||||
/// 重试当前集的票据(失败态的"重试"按钮)。
|
||||
Future<void> retryTicket() async {
|
||||
ticketError = null;
|
||||
@@ -238,6 +262,36 @@ class PlayerLogic extends ChangeNotifier {
|
||||
unawaited(selectEpisode(session.currentIndex));
|
||||
}
|
||||
|
||||
/// 金币解锁当前集;成功后强制刷新票据并直接起播。
|
||||
Future<bool> unlockEpisode(int index) async {
|
||||
final service = wallet;
|
||||
if (service == null || index < 0 || index >= sessionEpisodes.length) {
|
||||
return false;
|
||||
}
|
||||
final episode = sessionEpisodes[index];
|
||||
unlockingEpisodeId = episode.id;
|
||||
unlockError = null;
|
||||
notify();
|
||||
try {
|
||||
final result = await service.unlock(episode.id);
|
||||
if (result == null || !result.unlocked) {
|
||||
unlockError = service.unlockError;
|
||||
return false;
|
||||
}
|
||||
final ready = await ensureTicket(index, forceRefresh: true);
|
||||
if (ready) {
|
||||
await session.select(
|
||||
index,
|
||||
preloadIndex: nextVisibleIndex(index),
|
||||
);
|
||||
}
|
||||
return ready;
|
||||
} finally {
|
||||
unlockingEpisodeId = null;
|
||||
if (isMounted()) notify();
|
||||
}
|
||||
}
|
||||
|
||||
void onPageUpdated(PlayerPage previous) {
|
||||
if (previous.active != active) {
|
||||
session.setRouteVisible(active && visibleIndices.isNotEmpty);
|
||||
@@ -562,7 +616,12 @@ class PlayerLogic extends ChangeNotifier {
|
||||
if (!context.mounted) return;
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => PlayerPage(drama: drama, initialIndex: index),
|
||||
builder: (_) => PlayerPage(
|
||||
drama: drama,
|
||||
initialIndex: index,
|
||||
wallet: wallet,
|
||||
downloads: downloads,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (isMounted()) session.setRouteVisible(active);
|
||||
|
||||
@@ -10,9 +10,11 @@ import 'package:video_player/video_player.dart';
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/models/play_ticket.dart';
|
||||
import '../../core/data/services/favorite_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/interaction_controller.dart';
|
||||
import '../../core/data/services/playback_session.dart';
|
||||
import '../../core/data/services/video_player_port.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/formatting/error_text.dart';
|
||||
import '../../core/formatting/localized_content.dart';
|
||||
import '../../core/platform/haptics.dart';
|
||||
@@ -48,6 +50,8 @@ class PlayerPage extends StatefulWidget {
|
||||
this.feedDramas,
|
||||
this.onDramaChanged,
|
||||
this.onImmersiveChanged,
|
||||
this.wallet,
|
||||
this.downloads,
|
||||
});
|
||||
|
||||
final Drama drama;
|
||||
@@ -64,6 +68,8 @@ class PlayerPage extends StatefulWidget {
|
||||
final List<Drama>? feedDramas;
|
||||
final ValueChanged<Drama>? onDramaChanged;
|
||||
final ValueChanged<bool>? onImmersiveChanged;
|
||||
final WalletController? wallet;
|
||||
final DownloadController? downloads;
|
||||
|
||||
@override
|
||||
State<PlayerPage> createState() => _PlayerPageState();
|
||||
@@ -80,6 +86,8 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
|
||||
logic = PlayerBinding().create(
|
||||
history: context.read<WatchHistoryRepository>(),
|
||||
playback: context.read<PlaybackRepository>(),
|
||||
wallet: widget.wallet,
|
||||
downloads: widget.downloads,
|
||||
);
|
||||
logic.attach(widget, isMounted: () => mounted);
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
@@ -285,6 +293,11 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
|
||||
episode: episode,
|
||||
accessType: logic.blockedTicket?.accessType,
|
||||
unlockCoin: logic.blockedTicket?.unlockCoin ?? 0,
|
||||
unlocking: logic.unlockingEpisodeId == episode.id,
|
||||
error: logic.unlockError,
|
||||
onUnlock: logic.wallet == null
|
||||
? null
|
||||
: () => _unlockEpisode(context, index),
|
||||
),
|
||||
// 没有票据信息时的兜底(例如详情里就没地址、也没走票据流程)
|
||||
if (selected &&
|
||||
@@ -484,6 +497,21 @@ class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
|
||||
setState(() => _playbackSpeed = selected);
|
||||
await logic.setPlaybackSpeed(selected);
|
||||
}
|
||||
|
||||
Future<void> _unlockEpisode(BuildContext context, int index) async {
|
||||
if (!await ensureSignedIn(context)) return;
|
||||
if (!context.mounted) return;
|
||||
final ok = await logic.unlockEpisode(index);
|
||||
if (!context.mounted || ok) return;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
errorText(l10n, logic.unlockError, l10n.unlockFailed),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 不可播放提示:文案由后端返回的 `accessType` 驱动(契约 §1.4),前端不自行推断。
|
||||
@@ -493,12 +521,18 @@ class _BlockedNotice extends StatelessWidget {
|
||||
required this.episode,
|
||||
required this.accessType,
|
||||
required this.unlockCoin,
|
||||
required this.unlocking,
|
||||
required this.error,
|
||||
required this.onUnlock,
|
||||
});
|
||||
|
||||
final AppLocalizations l10n;
|
||||
final Episode episode;
|
||||
final String? accessType;
|
||||
final int unlockCoin;
|
||||
final bool unlocking;
|
||||
final String? error;
|
||||
final VoidCallback? onUnlock;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -521,7 +555,12 @@ class _BlockedNotice extends StatelessWidget {
|
||||
coinLabel: needsUnlock && unlockCoin > 0
|
||||
? '$unlockCoin ${l10n.coins}'
|
||||
: null,
|
||||
footnote: needsUnlock ? l10n.unlockComingSoon : null,
|
||||
footnote: needsUnlock && error != null
|
||||
? errorText(l10n, error, l10n.unlockFailed)
|
||||
: null,
|
||||
actionLabel: needsUnlock ? l10n.unlockWithCoins : null,
|
||||
busy: unlocking,
|
||||
onAction: needsUnlock ? onUnlock : null,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -535,12 +574,18 @@ class _UnlockCard extends StatelessWidget {
|
||||
required this.title,
|
||||
required this.coinLabel,
|
||||
required this.footnote,
|
||||
this.actionLabel,
|
||||
this.busy = false,
|
||||
this.onAction,
|
||||
});
|
||||
|
||||
final bool locked;
|
||||
final String title;
|
||||
final String? coinLabel;
|
||||
final String? footnote;
|
||||
final String? actionLabel;
|
||||
final bool busy;
|
||||
final VoidCallback? onAction;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -601,6 +646,34 @@ class _UnlockCard extends StatelessWidget {
|
||||
style: const TextStyle(color: AppColors.muted, fontSize: 12),
|
||||
),
|
||||
],
|
||||
if (actionLabel != null) ...[
|
||||
const SizedBox(height: 14),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 40,
|
||||
child: FilledButton(
|
||||
key: const Key('unlock-with-coins'),
|
||||
onPressed: busy ? null : onAction,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.gold,
|
||||
foregroundColor: AppColors.onGold,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
),
|
||||
child: busy
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(
|
||||
actionLabel!,
|
||||
style: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/models/wallet.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/formatting/error_text.dart';
|
||||
import '../../core/formatting/localized_date_time.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/theme/app_dimens.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
/// 金币钱包:余额、累计收支与最近流水。
|
||||
class WalletPage extends StatefulWidget {
|
||||
const WalletPage({super.key});
|
||||
|
||||
@override
|
||||
State<WalletPage> createState() => _WalletPageState();
|
||||
}
|
||||
|
||||
class _WalletPageState extends State<WalletPage> {
|
||||
bool _requested = false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_requested) return;
|
||||
_requested = true;
|
||||
final wallet = context.read<WalletController>();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) unawaited(wallet.load());
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final wallet = context.watch<WalletController>();
|
||||
return Theme(
|
||||
data: AppTheme.dark(),
|
||||
child: Scaffold(
|
||||
key: const Key('wallet-page'),
|
||||
backgroundColor: AppColors.ink,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColors.ink,
|
||||
foregroundColor: AppColors.onSurface,
|
||||
title: Text(l10n.wallet),
|
||||
),
|
||||
body: SafeArea(top: false, child: _body(l10n, wallet)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(AppLocalizations l10n, WalletController wallet) {
|
||||
if (wallet.loading && wallet.snapshot == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final snapshot = wallet.snapshot;
|
||||
if (snapshot == null) {
|
||||
return EmptyState(
|
||||
key: const Key('wallet-error'),
|
||||
icon: Icons.account_balance_wallet_outlined,
|
||||
title: errorText(l10n, wallet.error, l10n.walletLoadFailed),
|
||||
actionLabel: l10n.retry,
|
||||
actionKey: const Key('wallet-retry'),
|
||||
onAction: () => unawaited(wallet.load()),
|
||||
);
|
||||
}
|
||||
return RefreshIndicator(
|
||||
onRefresh: wallet.load,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 28),
|
||||
children: [
|
||||
_BalanceHero(wallet: snapshot.wallet),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _SummaryTile(
|
||||
icon: Icons.add_card_rounded,
|
||||
label: l10n.totalRecharged,
|
||||
value: snapshot.wallet.totalRechargedCoin,
|
||||
color: AppColors.success,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: _SummaryTile(
|
||||
icon: Icons.local_fire_department_rounded,
|
||||
label: l10n.totalConsumed,
|
||||
value: snapshot.wallet.totalConsumedCoin,
|
||||
color: AppColors.accent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
Text(
|
||||
l10n.coinLedger,
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: AppDimens.sectionTitle,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (snapshot.ledger.isEmpty)
|
||||
_LedgerEmpty(message: l10n.noCoinLedger)
|
||||
else
|
||||
for (final entry in snapshot.ledger) ...[
|
||||
_LedgerTile(entry: entry),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BalanceHero extends StatelessWidget {
|
||||
const _BalanceHero({required this.wallet});
|
||||
|
||||
final CoinWallet wallet;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return Container(
|
||||
key: const Key('wallet-balance-card'),
|
||||
padding: const EdgeInsets.fromLTRB(20, 22, 20, 20),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFF2B2116), Color(0xFF17171D)],
|
||||
),
|
||||
border: Border.all(color: AppColors.gold.withValues(alpha: 0.35)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.gold.withValues(alpha: 0.08),
|
||||
blurRadius: 28,
|
||||
offset: const Offset(0, 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 38,
|
||||
height: 38,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.gold.withValues(alpha: 0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.monetization_on_rounded,
|
||||
color: AppColors.gold,
|
||||
size: 21,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
l10n.coinBalance,
|
||||
style: const TextStyle(
|
||||
color: AppColors.muted,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${wallet.coinBalance}',
|
||||
key: const Key('wallet-balance'),
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: 42,
|
||||
height: 1,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 5),
|
||||
child: Text(
|
||||
l10n.coins,
|
||||
style: const TextStyle(
|
||||
color: AppColors.gold,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SummaryTile extends StatelessWidget {
|
||||
const _SummaryTile({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.color,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final int value;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.card,
|
||||
borderRadius: BorderRadius.circular(AppDimens.cardRadius),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, color: color, size: 18),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
'$value',
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(color: AppColors.subtle, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LedgerTile extends StatelessWidget {
|
||||
const _LedgerTile({required this.entry});
|
||||
|
||||
final CoinLedgerEntry entry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final positive = entry.changeAmount >= 0;
|
||||
final color = positive ? AppColors.success : AppColors.accent;
|
||||
final amount = positive ? '+${entry.changeAmount}' : '${entry.changeAmount}';
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.card,
|
||||
borderRadius: BorderRadius.circular(AppDimens.cardRadius),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(
|
||||
positive ? Icons.south_west_rounded : Icons.north_east_rounded,
|
||||
color: color,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_ledgerLabel(context, entry.bizType),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
if (entry.remark.isNotEmpty) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
entry.remark,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.subtle,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (entry.createdAt != null) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
formatLocalizedDateTime(context, entry.createdAt!),
|
||||
style: const TextStyle(
|
||||
color: AppColors.subtle,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
amount,
|
||||
key: Key('wallet-ledger-${entry.id}'),
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${entry.balanceAfter}',
|
||||
style: const TextStyle(color: AppColors.subtle, fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _ledgerLabel(BuildContext context, String bizType) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return switch (bizType) {
|
||||
'UNLOCK' => l10n.ledgerUnlock,
|
||||
'RECHARGE' || 'ORDER' => l10n.ledgerRecharge,
|
||||
'REFUND' => l10n.ledgerRefund,
|
||||
_ => l10n.ledgerAdjustment,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class _LedgerEmpty extends StatelessWidget {
|
||||
const _LedgerEmpty({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 22),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.card,
|
||||
borderRadius: BorderRadius.circular(AppDimens.cardRadius),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.receipt_long_outlined, color: AppColors.subtle),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
message,
|
||||
style: const TextStyle(color: AppColors.subtle, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user