sync
This commit is contained in:
1 parent
0b3282da5c
commit
24ccd628d1
43 files changed
+2099
-1490
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/strings.dart';
|
||||
import 'music_risk_feature_view.dart';
|
||||
|
||||
/// 收藏品获取:逻辑参考 `eaquira/action/UnlockMusic.py`,
|
||||
/// 通过上传 userItemList 道具获取收藏品 (UpsertUserAllApi)。
|
||||
///
|
||||
/// itemKind: 1=姓名框 2=称号 3=头像 10=搭档 11=背景板 12=功能票
|
||||
class CollectiblesPage extends StatelessWidget {
|
||||
final int userId;
|
||||
final String? cookies;
|
||||
final int? loginDateTime;
|
||||
final int? loginId;
|
||||
final String? lastLoginDate;
|
||||
final Future<void> Function()? onLogoutRequested;
|
||||
|
||||
const CollectiblesPage({
|
||||
super.key,
|
||||
required this.userId,
|
||||
this.cookies,
|
||||
this.loginDateTime,
|
||||
this.loginId,
|
||||
this.lastLoginDate,
|
||||
this.onLogoutRequested,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(AppStrings.collectiblesFeatureTitle),
|
||||
),
|
||||
body: MusicRiskFeatureView(
|
||||
userId: userId,
|
||||
cookies: cookies,
|
||||
loginDateTime: loginDateTime,
|
||||
loginId: loginId,
|
||||
lastLoginDate: lastLoginDate,
|
||||
onLogoutRequested: onLogoutRequested,
|
||||
mode: MusicRiskFeatureMode.collectibles,
|
||||
featureTitle: AppStrings.collectiblesFeatureTitle,
|
||||
featureDesc: AppStrings.collectiblesFeatureDesc,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ class ConfigExportImportPage extends StatelessWidget {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text(AppStrings.importSuccess)),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (_) {
|
||||
if (context.mounted) {
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/responsive.dart';
|
||||
import '../config/strings.dart';
|
||||
import '../config/title_server_config.dart';
|
||||
import 'collectibles_page.dart';
|
||||
import 'unlock_music_page.dart';
|
||||
|
||||
/// 高危功能中转页:导航到 UnlockMusic (解锁歌曲) / 收藏品获取。
|
||||
/// 两个 feature 互相独立,各自的执行流程互不影响。
|
||||
class HighRiskFeaturePage extends StatefulWidget {
|
||||
final int userId;
|
||||
final String? cookies;
|
||||
|
||||
/// `loginDateTime` 来自 HomePage 启动时执行的 UserLoginApi。
|
||||
/// 为 `null` 时表示当前未持有有效登录态。
|
||||
final int? loginDateTime;
|
||||
|
||||
/// UserLoginApi 返回的 loginId / lastLoginDate, 组装 UserAll 需要。
|
||||
final int? loginId;
|
||||
final String? lastLoginDate;
|
||||
|
||||
/// 由 HomePage 负责发送 logout 包。
|
||||
final Future<void> Function()? onLogoutRequested;
|
||||
|
||||
const HighRiskFeaturePage({
|
||||
super.key,
|
||||
required this.userId,
|
||||
this.cookies,
|
||||
this.loginDateTime,
|
||||
this.loginId,
|
||||
this.lastLoginDate,
|
||||
this.onLogoutRequested,
|
||||
});
|
||||
|
||||
@override
|
||||
State<HighRiskFeaturePage> createState() => _HighRiskFeaturePageState();
|
||||
}
|
||||
|
||||
class _HighRiskFeaturePageState extends State<HighRiskFeaturePage> {
|
||||
Timer? _cooldownTimer;
|
||||
int _cooldownRemaining = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_syncCooldown();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant HighRiskFeaturePage oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.loginDateTime != widget.loginDateTime) {
|
||||
_syncCooldown();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_cooldownTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _syncCooldown() {
|
||||
_cooldownTimer?.cancel();
|
||||
final loginDateTime = widget.loginDateTime;
|
||||
if (loginDateTime == null) {
|
||||
_cooldownRemaining = 0;
|
||||
return;
|
||||
}
|
||||
_cooldownRemaining = _computeRemaining(loginDateTime);
|
||||
if (_cooldownRemaining <= 0) return;
|
||||
_cooldownTimer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (!mounted) return;
|
||||
final remaining = _computeRemaining(loginDateTime);
|
||||
setState(() => _cooldownRemaining = remaining);
|
||||
if (remaining <= 0) {
|
||||
_cooldownTimer?.cancel();
|
||||
_cooldownTimer = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int _computeRemaining(int loginDateTime) {
|
||||
final nowSec = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
final elapsed = nowSec - loginDateTime;
|
||||
final remaining = AppStrings.ticketCooldownSeconds - elapsed;
|
||||
return remaining < 0 ? 0 : remaining;
|
||||
}
|
||||
|
||||
void _openUnlockMusic() {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => UnlockMusicPage(
|
||||
userId: widget.userId,
|
||||
cookies: widget.cookies,
|
||||
loginDateTime: widget.loginDateTime,
|
||||
loginId: widget.loginId,
|
||||
lastLoginDate: widget.lastLoginDate,
|
||||
onLogoutRequested: widget.onLogoutRequested,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _openCollectibles() {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CollectiblesPage(
|
||||
userId: widget.userId,
|
||||
cookies: widget.cookies,
|
||||
loginDateTime: widget.loginDateTime,
|
||||
loginId: widget.loginId,
|
||||
lastLoginDate: widget.lastLoginDate,
|
||||
onLogoutRequested: widget.onLogoutRequested,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
if (!TitleServerConfigHolder().isConfigured) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.settings_ethernet,
|
||||
size: 48, color: theme.colorScheme.primary),
|
||||
const SizedBox(height: 16),
|
||||
Text(AppStrings.ticketNotConfigured,
|
||||
style: theme.textTheme.titleMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: responsiveMaxWidth(context)),
|
||||
child: Column(
|
||||
children: [
|
||||
if (widget.loginDateTime == null) _buildNotLoggedInBanner(theme),
|
||||
if (widget.loginDateTime != null && _cooldownRemaining > 0)
|
||||
_buildCooldownBanner(theme),
|
||||
_buildDescCard(theme),
|
||||
const SizedBox(height: 12),
|
||||
_buildNavCard(
|
||||
theme,
|
||||
icon: Icons.lock_open,
|
||||
title: AppStrings.unlockFeatureTitle,
|
||||
desc: AppStrings.unlockFeatureDesc,
|
||||
onTap: _openUnlockMusic,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildNavCard(
|
||||
theme,
|
||||
icon: Icons.card_giftcard,
|
||||
title: AppStrings.collectiblesFeatureTitle,
|
||||
desc: AppStrings.collectiblesFeatureDesc,
|
||||
onTap: _openCollectibles,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotLoggedInBanner(ThemeData theme) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.errorContainer,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.warning_amber_rounded,
|
||||
size: 18, color: theme.colorScheme.onErrorContainer),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
AppStrings.musicRiskHubNotLoggedIn,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCooldownBanner(ThemeData theme) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.tertiaryContainer.withValues(alpha: 0.5),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.timer_outlined,
|
||||
size: 18, color: theme.colorScheme.onTertiaryContainer),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
AppStrings.musicRiskHubCooldownNotice(_cooldownRemaining),
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onTertiaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDescCard(ThemeData theme) {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(
|
||||
color: theme.colorScheme.error.withValues(alpha: 0.4),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.warning_amber_rounded,
|
||||
size: 18, color: theme.colorScheme.error),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
AppStrings.musicRiskHubTitle,
|
||||
style: theme.textTheme.labelLarge?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
AppStrings.musicRiskHubDesc,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavCard(
|
||||
ThemeData theme, {
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String desc,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: theme.colorScheme.outline.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 28, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
desc,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+87
-96
@@ -3,26 +3,25 @@ import 'package:flutter/material.dart';
|
||||
import '../config/responsive.dart';
|
||||
import '../config/strings.dart';
|
||||
import '../config/title_server_config.dart';
|
||||
import '../models/session_model.dart';
|
||||
import '../models/user_data.dart';
|
||||
import '../models/user_preview.dart';
|
||||
import '../services/title_api_service.dart';
|
||||
import 'about_page.dart';
|
||||
import 'high_risk_feature_page.dart';
|
||||
import 'settings_page.dart';
|
||||
import 'ticket_page.dart';
|
||||
import 'transfer_package_page.dart';
|
||||
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
final int userId;
|
||||
final String token;
|
||||
final String? cookies;
|
||||
final bool forcePreviewApi;
|
||||
|
||||
const HomePage({
|
||||
super.key,
|
||||
required this.userId,
|
||||
required this.token,
|
||||
this.cookies,
|
||||
this.forcePreviewApi = false,
|
||||
});
|
||||
|
||||
@@ -34,16 +33,16 @@ class _HomePageState extends State<HomePage> {
|
||||
int _currentTab = 0;
|
||||
UserPreviewDataBean? _preview;
|
||||
UserDataBean? _userData;
|
||||
UserLoginResult? _login;
|
||||
String? _error;
|
||||
bool _loading = true;
|
||||
bool _loggingOut = false;
|
||||
String? _sessionCookies;
|
||||
|
||||
SessionModel get _session => SessionModel.instance;
|
||||
|
||||
static const _tabTitles = [
|
||||
AppStrings.tabHome,
|
||||
AppStrings.tabTickets,
|
||||
AppStrings.tabTransfer,
|
||||
AppStrings.tabRisk,
|
||||
AppStrings.tabSettings,
|
||||
AppStrings.tabAbout,
|
||||
];
|
||||
@@ -68,12 +67,12 @@ class _HomePageState extends State<HomePage> {
|
||||
_error = null;
|
||||
_preview = null;
|
||||
_userData = null;
|
||||
_login = null;
|
||||
});
|
||||
_session.setGameLogin(null);
|
||||
|
||||
final service = TitleApiService(
|
||||
TitleServerConfigHolder().config!,
|
||||
cookies: widget.cookies,
|
||||
cookies: _session.cookies,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -82,7 +81,7 @@ class _HomePageState extends State<HomePage> {
|
||||
token: widget.token,
|
||||
);
|
||||
if (!mounted) return;
|
||||
_sessionCookies = service.cookies;
|
||||
_session.updateCookies(service.cookies);
|
||||
setState(() => _preview = preview);
|
||||
|
||||
// isLogin == true => 已有人登录, 不再走完整登录, 直接展示 preview 概要
|
||||
@@ -92,17 +91,19 @@ class _HomePageState extends State<HomePage> {
|
||||
return;
|
||||
}
|
||||
|
||||
final login = await service.userLoginFull(
|
||||
await _session.loginGame(
|
||||
userId: widget.userId,
|
||||
token: widget.token,
|
||||
);
|
||||
if (!mounted) return;
|
||||
_sessionCookies = service.cookies;
|
||||
setState(() => _login = login);
|
||||
|
||||
final userData = await service.getUserDataTyped(widget.userId);
|
||||
final userDataService = TitleApiService(
|
||||
TitleServerConfigHolder().config!,
|
||||
cookies: _session.cookies,
|
||||
);
|
||||
final userData = await userDataService.getUserDataTyped(widget.userId);
|
||||
if (!mounted) return;
|
||||
_sessionCookies = service.cookies;
|
||||
_session.updateCookies(userDataService.cookies);
|
||||
setState(() {
|
||||
_userData = userData;
|
||||
_loading = false;
|
||||
@@ -129,23 +130,20 @@ class _HomePageState extends State<HomePage> {
|
||||
_error = null;
|
||||
});
|
||||
|
||||
final service = TitleApiService(
|
||||
TitleServerConfigHolder().config!,
|
||||
cookies: _sessionCookies ?? widget.cookies,
|
||||
);
|
||||
|
||||
try {
|
||||
final login = await service.userLoginFull(
|
||||
await _session.loginGame(
|
||||
userId: widget.userId,
|
||||
token: widget.token,
|
||||
);
|
||||
if (!mounted) return;
|
||||
_sessionCookies = service.cookies;
|
||||
setState(() => _login = login);
|
||||
|
||||
final service = TitleApiService(
|
||||
TitleServerConfigHolder().config!,
|
||||
cookies: _session.cookies,
|
||||
);
|
||||
final userData = await service.getUserDataTyped(widget.userId);
|
||||
if (!mounted) return;
|
||||
_sessionCookies = service.cookies;
|
||||
_session.updateCookies(service.cookies);
|
||||
setState(() {
|
||||
_userData = userData;
|
||||
_loading = false;
|
||||
@@ -166,30 +164,16 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
|
||||
Future<void> _logoutSession() async {
|
||||
final login = _login;
|
||||
if (login == null) return;
|
||||
if (!TitleServerConfigHolder().isConfigured) return;
|
||||
final service = TitleApiService(
|
||||
TitleServerConfigHolder().config!,
|
||||
cookies: _sessionCookies ?? widget.cookies,
|
||||
);
|
||||
try {
|
||||
await service.userLogout(
|
||||
userId: widget.userId,
|
||||
loginDateTime: login.loginDateTime,
|
||||
);
|
||||
} catch (_) {
|
||||
// best-effort
|
||||
}
|
||||
_login = null;
|
||||
await _session.logoutGame(userId: widget.userId);
|
||||
}
|
||||
|
||||
Future<void> _performLogoutAndExit() async {
|
||||
setState(() => _loggingOut = true);
|
||||
if (_login != null) {
|
||||
if (_session.gameLogin != null) {
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
await _logoutSession();
|
||||
}
|
||||
_session.reset();
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
@@ -199,61 +183,68 @@ class _HomePageState extends State<HomePage> {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return PopScope(
|
||||
canPop: !_loggingOut,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && !_loggingOut) {
|
||||
_performLogoutAndExit();
|
||||
}
|
||||
return ListenableBuilder(
|
||||
listenable: _session,
|
||||
builder: (context, _) {
|
||||
return PopScope(
|
||||
canPop: !_loggingOut,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && !_loggingOut) {
|
||||
_performLogoutAndExit();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: _loggingOut
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.arrow_back),
|
||||
onPressed: _loggingOut ? null : _performLogoutAndExit,
|
||||
),
|
||||
title: Text(_tabTitles[_currentTab]),
|
||||
),
|
||||
body: IndexedStack(
|
||||
index: _currentTab,
|
||||
children: [
|
||||
_buildBody(theme),
|
||||
TicketPage(
|
||||
userId: widget.userId,
|
||||
cookies: _session.cookies,
|
||||
loginDateTime: _session.gameLogin?.loginDateTime,
|
||||
playerRating: _userData?.playerRating ?? _preview?.playerRating ?? 0,
|
||||
onLogoutRequested: _session.gameLogin != null ? _logoutSession : null,
|
||||
),
|
||||
HighRiskFeaturePage(
|
||||
userId: widget.userId,
|
||||
cookies: _session.cookies,
|
||||
loginDateTime: _session.gameLogin?.loginDateTime,
|
||||
loginId: _session.gameLogin?.loginId,
|
||||
lastLoginDate: _session.gameLogin?.lastLoginDate,
|
||||
onLogoutRequested:
|
||||
_session.gameLogin != null ? _logoutSession : null,
|
||||
),
|
||||
SettingsPage(showAppBar: false),
|
||||
const AboutPage(),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: _currentTab,
|
||||
onDestinationSelected: (i) => setState(() => _currentTab = i),
|
||||
destinations: const [
|
||||
NavigationDestination(icon: Icon(Icons.home_outlined), selectedIcon: Icon(Icons.home), label: AppStrings.tabHome),
|
||||
NavigationDestination(icon: Icon(Icons.confirmation_number_outlined), selectedIcon: Icon(Icons.confirmation_number), label: AppStrings.tabTickets),
|
||||
NavigationDestination(icon: Icon(Icons.warning_outlined), selectedIcon: Icon(Icons.inventory_2), label: AppStrings.tabRisk),
|
||||
NavigationDestination(icon: Icon(Icons.settings_outlined), selectedIcon: Icon(Icons.settings), label: AppStrings.tabSettings),
|
||||
NavigationDestination(icon: Icon(Icons.info_outlined), selectedIcon: Icon(Icons.info), label: AppStrings.tabAbout),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: _loggingOut
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.arrow_back),
|
||||
onPressed: _loggingOut ? null : _performLogoutAndExit,
|
||||
),
|
||||
title: Text(_tabTitles[_currentTab]),
|
||||
),
|
||||
body: IndexedStack(
|
||||
index: _currentTab,
|
||||
children: [
|
||||
_buildBody(theme),
|
||||
TicketPage(
|
||||
userId: widget.userId,
|
||||
cookies: _sessionCookies ?? widget.cookies,
|
||||
loginDateTime: _login?.loginDateTime,
|
||||
playerRating: _userData?.playerRating ?? _preview?.playerRating ?? 0,
|
||||
onLogoutRequested: _login != null ? _logoutSession : null,
|
||||
),
|
||||
TransferPackagePage(
|
||||
userId: widget.userId,
|
||||
cookies: _sessionCookies ?? widget.cookies,
|
||||
loginDateTime: _login?.loginDateTime,
|
||||
playlogId: _login?.loginId,
|
||||
lastLoginDate: _login?.lastLoginDate,
|
||||
),
|
||||
SettingsPage(showAppBar: false),
|
||||
const AboutPage(),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: _currentTab,
|
||||
onDestinationSelected: (i) => setState(() => _currentTab = i),
|
||||
destinations: const [
|
||||
NavigationDestination(icon: Icon(Icons.home_outlined), selectedIcon: Icon(Icons.home), label: AppStrings.tabHome),
|
||||
NavigationDestination(icon: Icon(Icons.confirmation_number_outlined), selectedIcon: Icon(Icons.confirmation_number), label: AppStrings.tabTickets),
|
||||
NavigationDestination(icon: Icon(Icons.inventory_2_outlined), selectedIcon: Icon(Icons.inventory_2), label: AppStrings.tabTransfer),
|
||||
NavigationDestination(icon: Icon(Icons.settings_outlined), selectedIcon: Icon(Icons.settings), label: AppStrings.tabSettings),
|
||||
NavigationDestination(icon: Icon(Icons.info_outlined), selectedIcon: Icon(Icons.info), label: AppStrings.tabAbout),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -332,11 +323,11 @@ class _HomePageState extends State<HomePage> {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
if ((preview.isLogin || (widget.forcePreviewApi && _login == null)) && userData == null) {
|
||||
if ((preview.isLogin || (widget.forcePreviewApi && _session.gameLogin == null)) && userData == null) {
|
||||
return _buildPreviewOnly(
|
||||
theme,
|
||||
preview,
|
||||
showLoginButton: widget.forcePreviewApi && _login == null,
|
||||
showLoginButton: widget.forcePreviewApi && _session.gameLogin == null,
|
||||
onLoginPressed: _performLogin,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,914 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/responsive.dart';
|
||||
import '../config/strings.dart';
|
||||
import '../config/title_server_config.dart';
|
||||
import '../services/title_api_service.dart';
|
||||
import '../services/user_all_payload_builder.dart';
|
||||
|
||||
/// Dart port of `eaquira/action/UnlockMusic.py`:
|
||||
///
|
||||
/// - 拉取 GetUserData/Extend/Option/Rating/Charge/Activity/MissionData
|
||||
/// - 组装 UserAll payload (musicData 使用 eaquira settings 中的默认值)
|
||||
/// - 附加道具 (userItemList / isNewItemList)
|
||||
/// - UpsertUserAllApi 上传
|
||||
/// - 可选自动 UserLogout
|
||||
enum MusicRiskStep { idle, fetchData, upload, logout, complete, failed }
|
||||
|
||||
enum MusicRiskFeatureMode {
|
||||
/// 解锁歌曲与谱面 (itemKind 5/6/7)
|
||||
unlockMusic,
|
||||
|
||||
/// 收藏品获取 (itemKind 1/2/3/10/11/12)
|
||||
collectibles,
|
||||
}
|
||||
|
||||
class MusicRiskFeatureView extends StatefulWidget {
|
||||
final int userId;
|
||||
final String? cookies;
|
||||
|
||||
/// `loginDateTime` 来自 HomePage 启动时执行的 UserLoginApi。
|
||||
/// 为 `null` 时表示当前未持有有效登录态(例如 isInherit 账号或登录失败)。
|
||||
final int? loginDateTime;
|
||||
|
||||
/// UserLoginApi 返回的 loginId / lastLoginDate, 组装 UserAll 需要。
|
||||
final int? loginId;
|
||||
final String? lastLoginDate;
|
||||
|
||||
/// 当用户勾选"完成后自动退出登录"时,由 HomePage 负责发送 logout 包。
|
||||
final Future<void> Function()? onLogoutRequested;
|
||||
|
||||
final MusicRiskFeatureMode mode;
|
||||
final String featureTitle;
|
||||
final String featureDesc;
|
||||
|
||||
const MusicRiskFeatureView({
|
||||
super.key,
|
||||
required this.userId,
|
||||
this.cookies,
|
||||
this.loginDateTime,
|
||||
this.loginId,
|
||||
this.lastLoginDate,
|
||||
this.onLogoutRequested,
|
||||
this.mode = MusicRiskFeatureMode.unlockMusic,
|
||||
required this.featureTitle,
|
||||
required this.featureDesc,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MusicRiskFeatureView> createState() => _MusicRiskFeatureViewState();
|
||||
}
|
||||
|
||||
class _MusicRiskFeatureViewState extends State<MusicRiskFeatureView> {
|
||||
/// eaquira `settings.musicData` 默认歌曲 (Amber Chronicle)。
|
||||
static const int _defaultMusicId = 11538;
|
||||
|
||||
// ── 解锁选项 (UnlockMusic) ──
|
||||
final _unlockMusicIdController = TextEditingController();
|
||||
bool _unlockMusic = false;
|
||||
bool _unlockMaster = false;
|
||||
bool _unlockRemaster = false;
|
||||
|
||||
// ── 收藏品选项 (Collectibles) ──
|
||||
final _itemIdController = TextEditingController();
|
||||
int _itemKind = 3;
|
||||
|
||||
// ── 运行状态 ──
|
||||
Map<String, Map<String, dynamic>>? _userAllData;
|
||||
bool _fetching = false;
|
||||
String? _fetchError;
|
||||
bool _running = false;
|
||||
bool _autoLogout = false;
|
||||
MusicRiskStep _step = MusicRiskStep.idle;
|
||||
String _stepMessage = '';
|
||||
String? _error;
|
||||
|
||||
// ── 冷却 ──
|
||||
Timer? _cooldownTimer;
|
||||
int _cooldownRemaining = 0;
|
||||
|
||||
bool get _isUnlock => widget.mode == MusicRiskFeatureMode.unlockMusic;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_syncCooldown();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant MusicRiskFeatureView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.loginDateTime != widget.loginDateTime) {
|
||||
_syncCooldown();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_cooldownTimer?.cancel();
|
||||
_unlockMusicIdController.dispose();
|
||||
_itemIdController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _syncCooldown() {
|
||||
_cooldownTimer?.cancel();
|
||||
final loginDateTime = widget.loginDateTime;
|
||||
if (loginDateTime == null) {
|
||||
_cooldownRemaining = 0;
|
||||
return;
|
||||
}
|
||||
_cooldownRemaining = _computeRemaining(loginDateTime);
|
||||
if (_cooldownRemaining <= 0) return;
|
||||
_cooldownTimer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (!mounted) return;
|
||||
final remaining = _computeRemaining(loginDateTime);
|
||||
setState(() => _cooldownRemaining = remaining);
|
||||
if (remaining <= 0) {
|
||||
_cooldownTimer?.cancel();
|
||||
_cooldownTimer = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int _computeRemaining(int loginDateTime) {
|
||||
final nowSec = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
final elapsed = nowSec - loginDateTime;
|
||||
final remaining = AppStrings.ticketCooldownSeconds - elapsed;
|
||||
return remaining < 0 ? 0 : remaining;
|
||||
}
|
||||
|
||||
void _updateStep(MusicRiskStep step, [String? message]) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_step = step;
|
||||
_stepMessage = message ?? '';
|
||||
});
|
||||
}
|
||||
|
||||
int _unlockMusicId() =>
|
||||
int.tryParse(_unlockMusicIdController.text.trim()) ?? -1;
|
||||
|
||||
int _itemId() => int.tryParse(_itemIdController.text.trim()) ?? -1;
|
||||
|
||||
/// eaquira UnlockMusic.py 使用 settings 中的默认 musicData。
|
||||
Map<String, dynamic> _buildMusicData() {
|
||||
return {
|
||||
'musicId': _isUnlock ? _unlockMusicId() : _defaultMusicId,
|
||||
'level': 0,
|
||||
'playCount': 1,
|
||||
'achievement': 0,
|
||||
'comboStatus': 0,
|
||||
'syncStatus': 0,
|
||||
'deluxscoreMax': 0,
|
||||
'scoreRank': 0,
|
||||
'extNum1': 0,
|
||||
};
|
||||
}
|
||||
|
||||
String? _validateInputs() {
|
||||
if (_isUnlock) {
|
||||
if (_unlockMusicId() <= 0) return AppStrings.unlockNeedMusicId;
|
||||
if (!_unlockMusic && !_unlockMaster && !_unlockRemaster) {
|
||||
return AppStrings.unlockNeedOption;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_itemId() <= 0) return AppStrings.collectiblesNeedItemId;
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _fetchData() async {
|
||||
if (!TitleServerConfigHolder().isConfigured) return;
|
||||
|
||||
setState(() {
|
||||
_fetching = true;
|
||||
_fetchError = null;
|
||||
_userAllData = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final config = TitleServerConfigHolder().config!;
|
||||
final service = TitleApiService(config, cookies: widget.cookies);
|
||||
final data = await service.fetchUserAllData(widget.userId);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_userAllData = data;
|
||||
_fetching = false;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_fetchError = e.toString();
|
||||
_fetching = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _run() async {
|
||||
final validationError = _validateInputs();
|
||||
if (validationError != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(validationError)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!TitleServerConfigHolder().isConfigured) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text(AppStrings.ticketNotConfigured)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final loginDateTime = widget.loginDateTime;
|
||||
final loginId = widget.loginId;
|
||||
if (loginDateTime == null || loginId == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_notLoggedInMessage)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (_cooldownRemaining > 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_cooldownNotice(_cooldownRemaining))),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final config = TitleServerConfigHolder().config!;
|
||||
final service = TitleApiService(config, cookies: widget.cookies);
|
||||
|
||||
setState(() {
|
||||
_running = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
Map<String, Map<String, dynamic>> data = _userAllData ?? const {};
|
||||
if (data.isEmpty) {
|
||||
_updateStep(MusicRiskStep.fetchData);
|
||||
data = await service.fetchUserAllData(widget.userId);
|
||||
if (mounted) setState(() => _userAllData = data);
|
||||
}
|
||||
|
||||
_updateStep(MusicRiskStep.upload);
|
||||
final musicData = _buildMusicData();
|
||||
final builder = UserAllPayloadBuilder(config);
|
||||
final packet = builder.build(
|
||||
userId: widget.userId,
|
||||
loginId: loginId,
|
||||
loginDateTime: loginDateTime,
|
||||
musicData: musicData,
|
||||
generalUserInfo: data,
|
||||
);
|
||||
|
||||
if (_isUnlock) {
|
||||
builder.applyMusicUnlockPatch(
|
||||
packet,
|
||||
musicData: musicData,
|
||||
musicId: _unlockMusicId(),
|
||||
unlockMusic: _unlockMusic,
|
||||
unlockMaster: _unlockMaster,
|
||||
unlockRemaster: _unlockRemaster,
|
||||
);
|
||||
} else {
|
||||
builder.applyItemListPatch(packet, items: [
|
||||
{'itemKind': _itemKind, 'itemId': _itemId(), 'stock': 1, 'isValid': true},
|
||||
]);
|
||||
}
|
||||
|
||||
await service.upsertUserAll(packet, widget.userId);
|
||||
|
||||
if (_autoLogout && widget.onLogoutRequested != null) {
|
||||
_updateStep(MusicRiskStep.logout);
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
await widget.onLogoutRequested!();
|
||||
}
|
||||
|
||||
_updateStep(
|
||||
MusicRiskStep.complete,
|
||||
_isUnlock
|
||||
? AppStrings.unlockMusicSuccess
|
||||
: AppStrings.collectiblesSuccess,
|
||||
);
|
||||
} on TitleApiException catch (e) {
|
||||
_updateStep(MusicRiskStep.failed, e.message);
|
||||
setState(() => _error = e.message);
|
||||
} catch (e) {
|
||||
_updateStep(MusicRiskStep.failed, e.toString());
|
||||
setState(() => _error = e.toString());
|
||||
} finally {
|
||||
if (mounted) setState(() => _running = false);
|
||||
}
|
||||
}
|
||||
|
||||
String get _notLoggedInMessage => _isUnlock
|
||||
? AppStrings.unlockNotLoggedIn
|
||||
: AppStrings.collectiblesNotLoggedIn;
|
||||
|
||||
String _cooldownNotice(int remaining) => _isUnlock
|
||||
? AppStrings.unlockCooldownNotice(remaining)
|
||||
: AppStrings.collectiblesCooldownNotice(remaining);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
if (!TitleServerConfigHolder().isConfigured) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.settings_ethernet,
|
||||
size: 48, color: theme.colorScheme.primary),
|
||||
const SizedBox(height: 16),
|
||||
Text(AppStrings.ticketNotConfigured,
|
||||
style: theme.textTheme.titleMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: responsiveMaxWidth(context)),
|
||||
child: Column(
|
||||
children: [
|
||||
if (widget.loginDateTime == null) _buildNotLoggedInBanner(theme),
|
||||
if (widget.loginDateTime != null && _cooldownRemaining > 0)
|
||||
_buildCooldownBanner(theme),
|
||||
_buildDescCard(theme),
|
||||
const SizedBox(height: 12),
|
||||
if (_isUnlock)
|
||||
_buildUnlockCard(theme)
|
||||
else
|
||||
_buildCollectiblesCard(theme),
|
||||
const SizedBox(height: 12),
|
||||
_buildFetchCard(theme),
|
||||
const SizedBox(height: 12),
|
||||
_buildAutoLogoutToggle(theme),
|
||||
const SizedBox(height: 12),
|
||||
_buildRunButton(theme),
|
||||
if (_step != MusicRiskStep.idle) ...[
|
||||
const SizedBox(height: 16),
|
||||
_buildProgressCard(theme),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotLoggedInBanner(ThemeData theme) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.errorContainer,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.warning_amber_rounded,
|
||||
size: 18, color: theme.colorScheme.onErrorContainer),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_notLoggedInMessage,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCooldownBanner(ThemeData theme) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.tertiaryContainer.withValues(alpha: 0.5),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.timer_outlined,
|
||||
size: 18, color: theme.colorScheme.onTertiaryContainer),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_cooldownNotice(_cooldownRemaining),
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onTertiaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDescCard(ThemeData theme) {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: theme.colorScheme.outline.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
_isUnlock ? Icons.lock_open : Icons.card_giftcard,
|
||||
size: 18,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.featureTitle,
|
||||
style: theme.textTheme.labelLarge?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
widget.featureDesc,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUnlockCard(ThemeData theme) {
|
||||
final enabled = !_running;
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: theme.colorScheme.outline.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _unlockMusicIdController,
|
||||
enabled: enabled,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppStrings.unlockMusicIdLabel,
|
||||
hintText: AppStrings.unlockMusicIdHint,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(14),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
_buildUnlockCheckbox(
|
||||
theme,
|
||||
value: _unlockMusic,
|
||||
label: AppStrings.unlockMusicOption,
|
||||
enabled: enabled,
|
||||
onChanged: (v) => setState(() => _unlockMusic = v),
|
||||
),
|
||||
_buildUnlockCheckbox(
|
||||
theme,
|
||||
value: _unlockMaster,
|
||||
label: AppStrings.unlockMasterOption,
|
||||
enabled: enabled,
|
||||
onChanged: (v) => setState(() => _unlockMaster = v),
|
||||
),
|
||||
_buildUnlockCheckbox(
|
||||
theme,
|
||||
value: _unlockRemaster,
|
||||
label: AppStrings.unlockRemasterOption,
|
||||
enabled: enabled,
|
||||
onChanged: (v) => setState(() => _unlockRemaster = v),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUnlockCheckbox(
|
||||
ThemeData theme, {
|
||||
required bool value,
|
||||
required String label,
|
||||
required bool enabled,
|
||||
required ValueChanged<bool> onChanged,
|
||||
}) {
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: enabled ? () => onChanged(!value) : null,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 2),
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: value,
|
||||
onChanged: enabled ? (v) => onChanged(v ?? false) : null,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: enabled
|
||||
? null
|
||||
: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCollectiblesCard(ThemeData theme) {
|
||||
final enabled = !_running;
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: theme.colorScheme.outline.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildDropdown(
|
||||
value: _itemKind,
|
||||
label: AppStrings.collectiblesItemKindLabel,
|
||||
items: [
|
||||
for (final kind in AppStrings.collectiblesItemKinds)
|
||||
DropdownMenuItem(
|
||||
value: kind,
|
||||
child: Text(
|
||||
'${AppStrings.collectiblesItemKindName(kind)} ($kind)',
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (v) => setState(() => _itemKind = v),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _itemIdController,
|
||||
enabled: enabled,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppStrings.collectiblesItemIdLabel,
|
||||
hintText: AppStrings.collectiblesItemIdHint,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFetchCard(ThemeData theme) {
|
||||
final hasData = _userAllData != null;
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(
|
||||
color: hasData
|
||||
? Colors.green.withValues(alpha: 0.5)
|
||||
: theme.colorScheme.outline.withValues(alpha: 0.3),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
hasData ? Icons.check_circle : Icons.download,
|
||||
size: 18,
|
||||
color: hasData ? Colors.green : theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
hasData
|
||||
? AppStrings.unlockFetched
|
||||
: AppStrings.unlockNoData,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: hasData
|
||||
? Colors.green
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 32,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _fetching || _running ? null : _fetchData,
|
||||
icon: _fetching
|
||||
? const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.refresh, size: 16),
|
||||
label: Text(
|
||||
_fetching
|
||||
? AppStrings.unlockFetching
|
||||
: hasData
|
||||
? AppStrings.unlockRefetch
|
||||
: AppStrings.unlockFetchData,
|
||||
style: theme.textTheme.labelSmall,
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_fetchError != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.errorContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
_fetchError!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onErrorContainer,
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAutoLogoutToggle(ThemeData theme) {
|
||||
final enabled = widget.onLogoutRequested != null && !_running;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: enabled
|
||||
? () => setState(() => _autoLogout = !_autoLogout)
|
||||
: null,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: _autoLogout,
|
||||
onChanged: enabled
|
||||
? (v) => setState(() => _autoLogout = v ?? false)
|
||||
: null,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
AppStrings.unlockAutoLogout,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: enabled
|
||||
? null
|
||||
: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRunButton(ThemeData theme) {
|
||||
final onCooldown = _cooldownRemaining > 0;
|
||||
final canRun = widget.loginDateTime != null &&
|
||||
widget.loginId != null &&
|
||||
!_running &&
|
||||
!onCooldown;
|
||||
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton.icon(
|
||||
onPressed: canRun ? _run : null,
|
||||
icon: _running
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: Icon(
|
||||
onCooldown
|
||||
? Icons.timer_outlined
|
||||
: (_isUnlock ? Icons.lock_open : Icons.card_giftcard),
|
||||
size: 20,
|
||||
),
|
||||
label: Text(
|
||||
_running
|
||||
? AppStrings.unlockRunning
|
||||
: onCooldown
|
||||
? AppStrings.ticketCooldownCountdown(_cooldownRemaining)
|
||||
: _isUnlock
|
||||
? AppStrings.unlockMusicRun
|
||||
: AppStrings.collectiblesRun,
|
||||
),
|
||||
style: FilledButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProgressCard(ThemeData theme) {
|
||||
final isFailed = _step == MusicRiskStep.failed;
|
||||
final isDone = _step == MusicRiskStep.complete;
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(
|
||||
color: isFailed
|
||||
? theme.colorScheme.error.withValues(alpha: 0.5)
|
||||
: isDone
|
||||
? Colors.green.withValues(alpha: 0.5)
|
||||
: theme.colorScheme.outline.withValues(alpha: 0.3),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_stepRow(MusicRiskStep.fetchData, AppStrings.unlockStepFetch, theme),
|
||||
_stepRow(
|
||||
MusicRiskStep.upload,
|
||||
_isUnlock
|
||||
? AppStrings.unlockStepUpload
|
||||
: AppStrings.collectiblesStepUpload,
|
||||
theme,
|
||||
),
|
||||
if (_autoLogout)
|
||||
_stepRow(MusicRiskStep.logout, AppStrings.stepLogout, theme),
|
||||
if (_stepMessage.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: isFailed
|
||||
? theme.colorScheme.errorContainer
|
||||
: isDone
|
||||
? Colors.green.withValues(alpha: 0.1)
|
||||
: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
_stepMessage,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
fontFamily: 'monospace',
|
||||
color: isFailed
|
||||
? theme.colorScheme.onErrorContainer
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.errorContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
_error!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onErrorContainer,
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _stepRow(MusicRiskStep step, String label, ThemeData theme) {
|
||||
IconData icon;
|
||||
Color? color;
|
||||
|
||||
if (_step == MusicRiskStep.failed && _step.index <= step.index) {
|
||||
icon = _step == step ? Icons.error : Icons.circle_outlined;
|
||||
color = _step == step
|
||||
? theme.colorScheme.error
|
||||
: theme.colorScheme.onSurfaceVariant;
|
||||
} else if (_step.index > step.index) {
|
||||
icon = Icons.check_circle;
|
||||
color = Colors.green;
|
||||
} else if (_step == step) {
|
||||
icon = Icons.sync;
|
||||
color = theme.colorScheme.primary;
|
||||
} else {
|
||||
icon = Icons.circle_outlined;
|
||||
color = theme.colorScheme.onSurfaceVariant;
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: color),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
label,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: _step.index >= step.index
|
||||
? theme.colorScheme.onSurface
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
fontWeight: _step == step ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdown({
|
||||
required int value,
|
||||
required String label,
|
||||
required List<DropdownMenuItem<int>> items,
|
||||
required ValueChanged<int> onChanged,
|
||||
}) {
|
||||
return DropdownButtonFormField<int>(
|
||||
initialValue: value,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(14),
|
||||
),
|
||||
items: items,
|
||||
onChanged: _running
|
||||
? null
|
||||
: (v) {
|
||||
if (v == null) return;
|
||||
onChanged(v);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,10 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadConfig();
|
||||
}
|
||||
|
||||
void _loadConfig() {
|
||||
final config = TitleServerConfigHolder().config;
|
||||
if (config != null) {
|
||||
_urlController.text = config.titleServerUrl;
|
||||
@@ -155,10 +159,13 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const ConfigExportImportPage()),
|
||||
);
|
||||
if (mounted) {
|
||||
_loadConfig();
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.import_export, size: 20),
|
||||
label: const Text(AppStrings.configExportImport),
|
||||
|
||||
@@ -42,16 +42,16 @@ class TicketPage extends StatefulWidget {
|
||||
|
||||
class _TicketPageState extends State<TicketPage> {
|
||||
static const _ticketNameMap = {
|
||||
2: '2倍功能票',
|
||||
4: '4倍功能票',
|
||||
5: '5倍功能票'
|
||||
2: '2倍票',
|
||||
4: '4倍票',
|
||||
5: '5倍票'
|
||||
};
|
||||
|
||||
TicketStep _step = TicketStep.idle;
|
||||
String _stepMessage = '';
|
||||
String? _error;
|
||||
bool _running = false;
|
||||
bool _autoLogout = false;
|
||||
bool _autoLogout = true;
|
||||
|
||||
List<Map<String, dynamic>>? _tickets;
|
||||
bool _ticketsLoading = false;
|
||||
@@ -187,6 +187,15 @@ class _TicketPageState extends State<TicketPage> {
|
||||
return;
|
||||
}
|
||||
|
||||
final selectedTicket = _findTicket(_selectedTicketId!);
|
||||
if (selectedTicket != null &&
|
||||
(selectedTicket['stock'] as num?)?.toInt() != 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text(AppStrings.ticketStockNotEmpty)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final config = TitleServerConfigHolder().config!;
|
||||
final service = TitleApiService(config, cookies: widget.cookies);
|
||||
final ticketId = _selectedTicketId!;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../config/strings.dart';
|
||||
import 'music_risk_feature_view.dart';
|
||||
|
||||
/// Port of `eaquira/action/UnlockMusic.py`:
|
||||
/// 上传 itemKind 5/6/7 道具解锁歌曲与谱面 (UpsertUserAllApi)。
|
||||
class UnlockMusicPage extends StatelessWidget {
|
||||
final int userId;
|
||||
final String? cookies;
|
||||
final int? loginDateTime;
|
||||
final int? loginId;
|
||||
final String? lastLoginDate;
|
||||
final Future<void> Function()? onLogoutRequested;
|
||||
|
||||
const UnlockMusicPage({
|
||||
super.key,
|
||||
required this.userId,
|
||||
this.cookies,
|
||||
this.loginDateTime,
|
||||
this.loginId,
|
||||
this.lastLoginDate,
|
||||
this.onLogoutRequested,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(AppStrings.unlockFeatureTitle),
|
||||
),
|
||||
body: MusicRiskFeatureView(
|
||||
userId: userId,
|
||||
cookies: cookies,
|
||||
loginDateTime: loginDateTime,
|
||||
loginId: loginId,
|
||||
lastLoginDate: lastLoginDate,
|
||||
onLogoutRequested: onLogoutRequested,
|
||||
mode: MusicRiskFeatureMode.unlockMusic,
|
||||
featureTitle: AppStrings.unlockFeatureTitle,
|
||||
featureDesc: AppStrings.unlockFeatureDesc,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user