fix(mining-app): update splash page theme and fix token refresh

- Update splash_page.dart to orange theme (#FF6B00) matching other pages
- Change app name from "榴莲挖矿" to "榴莲生态"
- Fix refreshTokenIfNeeded to properly throw on failure instead of
  silently calling logout (which caused Riverpod ref errors)
- Clear local storage directly on refresh failure without remote API call

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-12 19:32:31 -08:00
parent 9037c2da97
commit 41f142124b
2 changed files with 27 additions and 13 deletions

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../../core/router/routes.dart'; import '../../../core/router/routes.dart';
import '../../../core/constants/app_colors.dart';
import '../../providers/user_providers.dart'; import '../../providers/user_providers.dart';
class SplashPage extends ConsumerStatefulWidget { class SplashPage extends ConsumerStatefulWidget {
@ -13,6 +12,12 @@ class SplashPage extends ConsumerStatefulWidget {
} }
class _SplashPageState extends ConsumerState<SplashPage> { class _SplashPageState extends ConsumerState<SplashPage> {
// -
static const Color _orange = Color(0xFFFF6B00);
static const Color _darkText = Color(0xFF1F2937);
static const Color _grayText = Color(0xFF6B7280);
static const Color _serenade = Color(0xFFFFF7ED);
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -49,7 +54,7 @@ class _SplashPageState extends ConsumerState<SplashPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: AppColors.primary, backgroundColor: Colors.white,
body: Center( body: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -58,20 +63,20 @@ class _SplashPageState extends ConsumerState<SplashPage> {
width: 100, width: 100,
height: 100, height: 100,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: _serenade,
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(24),
), ),
child: const Icon( child: const Icon(
Icons.eco, Icons.eco,
size: 60, size: 60,
color: AppColors.primary, color: _orange,
), ),
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
const Text( const Text(
'榴莲挖矿', '榴莲生态',
style: TextStyle( style: TextStyle(
color: Colors.white, color: _darkText,
fontSize: 28, fontSize: 28,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
@ -80,14 +85,18 @@ class _SplashPageState extends ConsumerState<SplashPage> {
const Text( const Text(
'绿色财富 共享未来', '绿色财富 共享未来',
style: TextStyle( style: TextStyle(
color: Colors.white70, color: _grayText,
fontSize: 16, fontSize: 16,
), ),
), ),
const SizedBox(height: 48), const SizedBox(height: 48),
const CircularProgressIndicator( const SizedBox(
color: Colors.white, width: 24,
strokeWidth: 2, height: 24,
child: CircularProgressIndicator(
color: _orange,
strokeWidth: 2,
),
), ),
], ],
), ),

View File

@ -181,14 +181,19 @@ class UserNotifier extends StateNotifier<UserState> {
} }
Future<void> refreshTokenIfNeeded() async { Future<void> refreshTokenIfNeeded() async {
if (state.refreshToken == null) return; if (state.refreshToken == null) {
throw Exception('No refresh token available');
}
try { try {
final newAccessToken = await _authDataSource.refreshToken(state.refreshToken!); final newAccessToken = await _authDataSource.refreshToken(state.refreshToken!);
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
await prefs.setString('access_token', newAccessToken); await prefs.setString('access_token', newAccessToken);
state = state.copyWith(accessToken: newAccessToken); state = state.copyWith(accessToken: newAccessToken);
} catch (e) { } catch (e) {
await logout(); // logout API
await _clearStorage();
state = UserState();
rethrow;
} }
} }