refactor(apps): 主题系统迁移至 ColorScheme + 扩展架构并支持 Dark Mode

This commit is contained in:
qzl
2026-03-27 19:07:39 +08:00
parent ecc1ec6ce4
commit ae29a8209b
146 changed files with 4301 additions and 3200 deletions
@@ -1,11 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:social_app/core/constants/app_constants.dart';
import 'package:social_app/core/config/env.dart';
import 'package:social_app/app/di/injection.dart';
import 'package:social_app/app/router/app_routes.dart';
import 'package:social_app/core/l10n/l10n.dart';
import 'package:social_app/core/theme/design_tokens.dart';
import 'package:social_app/core/auth/session_controller.dart';
import 'package:social_app/data/models/user_profile.dart';
import 'package:social_app/data/repositories/friend_repository.dart';
import 'package:social_app/shared/widgets/app_button.dart';
import 'package:social_app/shared/widgets/app_loading_indicator.dart';
import 'package:social_app/shared/widgets/app_pressable.dart';
@@ -13,15 +15,10 @@ import 'package:social_app/shared/widgets/destructive_action_sheet.dart';
import 'package:social_app/shared/widgets/toast/toast.dart';
import 'package:social_app/shared/widgets/toast/toast_type.dart';
import 'package:social_app/core/utils/phone_display_formatter.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_bloc.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_event.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_state.dart';
import 'package:social_app/features/contacts/data/friends_api.dart';
import 'package:social_app/features/settings/data/settings_api.dart';
import 'package:social_app/features/settings/data/services/automation_jobs_api.dart';
import 'package:social_app/features/settings/data/services/settings_user_cache.dart';
import 'package:social_app/features/contacts/data/users/models/user_response.dart';
import 'package:social_app/features/home/presentation/navigation/home_return_policy.dart';
import 'package:social_app/features/settings/data/services/user_profile_cache_repository.dart';
import 'package:social_app/app/router/home_return_policy.dart';
import '../widgets/settings_page_scaffold.dart';
const settingsProfileEditButtonKey = ValueKey('settings_profile_edit_button');
@@ -35,11 +32,13 @@ class SettingsScreen extends StatefulWidget {
}
class _SettingsScreenState extends State<SettingsScreen> {
final FriendsApi _friendsApi = sl<FriendsApi>();
final FriendRepository _friendRepository = sl<FriendRepository>();
final SessionController _sessionController = sl<SessionController>();
final AutomationJobsApi _automationJobsApi = sl<AutomationJobsApi>();
final SettingsUserCache _userCache = sl<SettingsUserCache>();
final UserProfileCacheRepository _userCache =
sl<UserProfileCacheRepository>();
UserResponse? _user;
UserProfile? _user;
bool _isLoading = true;
int _friendsCount = 0;
String? _firstFriendName;
@@ -75,14 +74,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
try {
final friends = await _friendsApi.getFriends();
final friends = await _friendRepository.getFriends();
if (mounted) {
setState(() {
_friendsCount = friends.length;
_firstFriendName = friends.isNotEmpty
? friends.first.friend.username
: null;
_firstFriendName = friends.isNotEmpty ? friends.first.username : null;
});
}
} catch (e) {
@@ -128,13 +125,15 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
Widget _buildProfileHero() {
final colorScheme = Theme.of(context).colorScheme;
if (_isLoading) {
return Container(
width: double.infinity,
height: 120,
padding: const EdgeInsets.all(AppSpacing.xl),
decoration: BoxDecoration(
color: AppColors.white,
color: colorScheme.surface,
borderRadius: BorderRadius.circular(AppRadius.xxl),
),
child: const Center(child: AppLoadingIndicator(size: 22)),
@@ -151,16 +150,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
width: double.infinity,
padding: const EdgeInsets.all(AppSpacing.xl),
decoration: BoxDecoration(
gradient: const LinearGradient(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.white, AppColors.surfaceInfoLight],
colors: [colorScheme.surface, colorScheme.surfaceContainerLow],
),
borderRadius: BorderRadius.circular(AppRadius.xxl),
border: Border.all(color: AppColors.borderTertiary),
border: Border.all(color: colorScheme.outlineVariant),
boxShadow: [
BoxShadow(
color: AppColors.blue100.withValues(alpha: 0.35),
color: colorScheme.shadow.withValues(alpha: 0.2),
blurRadius: 14,
offset: const Offset(0, 4),
),
@@ -179,12 +178,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
borderRadius: BorderRadius.circular(32),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(
AppColors.blue400.r.toInt(),
AppColors.blue400.g.toInt(),
AppColors.blue400.b.toInt(),
0.2,
),
color: colorScheme.primary.withValues(alpha: 0.2),
blurRadius: 12,
offset: const Offset(0, 4),
),
@@ -201,10 +195,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
children: [
Text(
username,
style: const TextStyle(
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
color: AppColors.slate900,
color: colorScheme.onSurface,
),
overflow: TextOverflow.ellipsis,
),
@@ -214,7 +208,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
color: colorScheme.onSurfaceVariant,
),
),
],
@@ -235,17 +229,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Icon(
Icon(
Icons.edit,
size: 14,
color: AppColors.slate500,
color: colorScheme.onSurfaceVariant,
),
const SizedBox(height: 3),
Container(
width: 12,
height: 1.5,
decoration: BoxDecoration(
color: AppColors.slate400,
color: colorScheme.onSurfaceVariant,
borderRadius: BorderRadius.circular(
AppRadius.full,
),
@@ -267,37 +261,47 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
Widget _buildFreeBadge() {
final colorScheme = Theme.of(context).colorScheme;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [AppColors.blue50, AppColors.surfaceInfoLight],
colors: [
colorScheme.primaryContainer,
colorScheme.surfaceContainerLow,
],
),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColors.borderQuaternary),
border: Border.all(color: colorScheme.outlineVariant),
),
child: Text(
context.l10n.settingsFreeBadge,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: AppColors.blue600,
color: colorScheme.primary,
),
),
);
}
Widget _buildAvatarImage(String? avatarUrl) {
final colorScheme = Theme.of(context).colorScheme;
if (avatarUrl == null) {
return Container(
decoration: const BoxDecoration(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.blue100, AppColors.blue50],
colors: [
colorScheme.primaryContainer,
colorScheme.surfaceContainerLow,
],
),
),
child: const Icon(Icons.person, size: 28, color: AppColors.blue600),
child: Icon(Icons.person, size: 28, color: colorScheme.primary),
);
}
return Image.network(
@@ -307,33 +311,39 @@ class _SettingsScreenState extends State<SettingsScreen> {
height: 64,
errorBuilder: (context, error, stackTrace) {
return Container(
decoration: const BoxDecoration(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.blue100, AppColors.blue50],
colors: [
colorScheme.primaryContainer,
colorScheme.surfaceContainerLow,
],
),
),
child: const Icon(Icons.person, size: 28, color: AppColors.blue600),
child: Icon(Icons.person, size: 28, color: colorScheme.primary),
);
},
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Container(
decoration: const BoxDecoration(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.blue100, AppColors.blue50],
colors: [
colorScheme.primaryContainer,
colorScheme.surfaceContainerLow,
],
),
),
child: const Center(
child: Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(AppColors.blue600),
valueColor: AlwaysStoppedAnimation<Color>(colorScheme.primary),
),
),
),
@@ -374,7 +384,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
Expanded(
child: _buildActionCard(
icon: Icons.people,
iconColor: AppColors.blue500,
title: context.l10n.contactsTitle,
subtitle: _buildFriendsSubtitle(),
onTap: () => context.push(AppRoutes.contactsList),
@@ -384,7 +393,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
Expanded(
child: _buildActionCard(
icon: Icons.auto_awesome,
iconColor: AppColors.blue500,
title: context.l10n.settingsFeaturesTitle,
subtitle: _buildAutomationSubtitle(),
onTap: () => context.push(AppRoutes.settingsFeatures),
@@ -396,11 +404,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
Widget _buildActionCard({
required IconData icon,
required Color iconColor,
required String title,
required String subtitle,
required VoidCallback onTap,
}) {
final colorScheme = Theme.of(context).colorScheme;
return AppPressable(
onTap: onTap,
borderRadius: BorderRadius.circular(AppRadius.xl),
@@ -408,12 +417,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
constraints: const BoxConstraints(minHeight: 136),
padding: const EdgeInsets.all(AppSpacing.lg),
decoration: BoxDecoration(
color: AppColors.white,
color: colorScheme.surface,
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(color: AppColors.borderSecondary),
border: Border.all(color: colorScheme.outlineVariant),
boxShadow: [
BoxShadow(
color: AppColors.slate200.withValues(alpha: 0.45),
color: colorScheme.shadow.withValues(alpha: 0.15),
blurRadius: 8,
offset: const Offset(0, 2),
),
@@ -428,22 +437,26 @@ class _SettingsScreenState extends State<SettingsScreen> {
width: 36,
height: 36,
decoration: BoxDecoration(
color: AppColors.surfaceTertiary,
color: colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(10),
),
child: Icon(icon, size: 18, color: iconColor),
child: Icon(icon, size: 18, color: colorScheme.primary),
),
const Spacer(),
Icon(Icons.chevron_right, size: 16, color: AppColors.slate300),
Icon(
Icons.chevron_right,
size: 16,
color: colorScheme.onSurfaceVariant,
),
],
),
const SizedBox(height: AppSpacing.md),
Text(
title,
style: const TextStyle(
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.slate900,
color: colorScheme.onSurface,
),
),
const SizedBox(height: 2),
@@ -452,7 +465,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
color: colorScheme.onSurfaceVariant,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
@@ -464,19 +477,21 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
Widget _buildSubscriptionCard() {
final colorScheme = Theme.of(context).colorScheme;
return Container(
padding: const EdgeInsets.all(AppSpacing.lg),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.white, AppColors.surfaceInfoLight],
colors: [colorScheme.surface, colorScheme.surfaceContainerLow],
),
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(color: AppColors.borderTertiary),
border: Border.all(color: colorScheme.outlineVariant),
boxShadow: [
BoxShadow(
color: AppColors.slate200.withValues(alpha: 0.4),
color: colorScheme.shadow.withValues(alpha: 0.15),
blurRadius: 8,
offset: const Offset(0, 2),
),
@@ -491,21 +506,24 @@ class _SettingsScreenState extends State<SettingsScreen> {
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.blue100, AppColors.blue50],
colors: [
colorScheme.primaryContainer,
colorScheme.surfaceContainerLow,
],
),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: AppColors.blue200.withValues(alpha: 0.45),
color: colorScheme.primary.withValues(alpha: 0.2),
blurRadius: 6,
offset: const Offset(0, 1),
),
],
),
child: const Icon(
child: Icon(
Icons.workspace_premium,
size: 22,
color: AppColors.blue600,
color: colorScheme.primary,
),
),
const SizedBox(width: AppSpacing.md),
@@ -518,7 +536,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.slate900,
color: colorScheme.onSurface,
),
),
const SizedBox(height: 2),
@@ -527,7 +545,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
color: colorScheme.onSurfaceVariant,
),
),
],
@@ -536,13 +554,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [AppColors.blue500, AppColors.blue600],
gradient: LinearGradient(
colors: [
colorScheme.primary,
colorScheme.primary.withValues(alpha: 0.85),
],
),
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: const Color(0x4D60A5FA),
color: colorScheme.primary.withValues(alpha: 0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
@@ -553,7 +574,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: AppColors.white,
color: colorScheme.onPrimary,
),
),
),
@@ -563,11 +584,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
Widget _buildMenuCard(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Container(
decoration: BoxDecoration(
color: AppColors.white,
color: colorScheme.surface,
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(color: AppColors.borderSecondary),
border: Border.all(color: colorScheme.outlineVariant),
),
child: Column(
children: [
@@ -586,7 +609,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_buildMenuItem(
icon: Icons.system_update,
title: context.l10n.settingsMenuCheckUpdates,
trailing: 'v${AppConstants.version}',
trailing: 'v${Env.version}',
onTap: _checkForUpdates,
),
],
@@ -600,6 +623,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
String? trailing,
required VoidCallback onTap,
}) {
final colorScheme = Theme.of(context).colorScheme;
return AppPressable(
onTap: onTap,
borderRadius: BorderRadius.circular(AppRadius.md),
@@ -611,14 +636,14 @@ class _SettingsScreenState extends State<SettingsScreen> {
children: [
Row(
children: [
Icon(icon, size: 20, color: AppColors.slate500),
Icon(icon, size: 20, color: colorScheme.onSurfaceVariant),
const SizedBox(width: 10),
Text(
title,
style: const TextStyle(
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: AppColors.slate900,
color: colorScheme.onSurface,
),
),
],
@@ -628,17 +653,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
if (trailing != null) ...[
Text(
trailing,
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: AppColors.slate400,
color: colorScheme.onSurfaceVariant,
),
),
const SizedBox(width: 6),
],
const Icon(
Icon(
Icons.chevron_right,
size: 18,
color: AppColors.slate400,
color: colorScheme.onSurfaceVariant,
),
],
),
@@ -649,10 +674,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
Widget _buildDivider() {
final colorScheme = Theme.of(context).colorScheme;
return Container(
height: 1,
margin: const EdgeInsets.symmetric(horizontal: 14),
color: AppColors.slate100,
color: colorScheme.outlineVariant,
);
}
@@ -679,13 +706,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
return;
}
_userCache.invalidate();
final authBloc = context.read<AuthBloc>();
authBloc.add(AuthLoggedOut());
await _userCache.invalidate();
if (!mounted) {
return;
}
try {
await authBloc.stream
.firstWhere((state) => state is AuthUnauthenticated)
.timeout(const Duration(seconds: 5));
await _sessionController.logoutAndWaitUnauthenticated();
} catch (_) {
if (!mounted) return;
Toast.show(
@@ -703,8 +729,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
try {
final settingsApi = sl<SettingsApi>();
final result = await settingsApi.checkUpdates(
currentVersionCode: AppConstants.build,
currentVersionName: AppConstants.version,
currentVersionCode: Env.build,
currentVersionName: Env.version,
platform: 'android',
);