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,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
@@ -9,9 +10,9 @@ import '../../../../shared/widgets/app_button.dart';
import '../../../../shared/widgets/app_loading_indicator.dart';
import '../../../../shared/widgets/toast/toast.dart';
import '../../../../shared/widgets/toast/toast_type.dart';
import '../../data/services/settings_user_cache.dart';
import '../../../contacts/data/users/models/user_response.dart';
import '../../../contacts/data/users/users_api.dart';
import '../../../../data/models/user_profile.dart';
import '../../data/services/user_profile_cache_repository.dart';
import '../../data/services/user_profile_service.dart';
import '../widgets/account_section_card.dart';
import '../widgets/settings_page_scaffold.dart';
@@ -25,11 +26,11 @@ class EditProfileScreen extends StatefulWidget {
class _EditProfileScreenState extends State<EditProfileScreen> {
final _usernameController = TextEditingController();
final _bioController = TextEditingController();
final _usersApi = sl<UsersApi>();
final _userCache = sl<SettingsUserCache>();
final _userProfileService = sl<UserProfileService>();
final _userCache = sl<UserProfileCacheRepository>();
final _imagePicker = ImagePicker();
UserResponse? _user;
UserProfile? _user;
File? _selectedAvatar;
bool _isLoading = true;
bool _isSaving = false;
@@ -55,9 +56,9 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
}
try {
final user = await _usersApi.getMe();
final user = await _userProfileService.getMe();
if (mounted) {
_userCache.set(user);
unawaited(_userCache.setCached(user));
setState(() {
_user = user;
_usernameController.text = user.username;
@@ -115,7 +116,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
});
try {
await _usersApi.uploadAvatar(_selectedAvatar!);
await _userProfileService.uploadAvatar(_selectedAvatar!);
if (mounted) {
Toast.show(
context,
@@ -183,8 +184,8 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
username: usernameChanged ? newUsername : null,
bio: bioChanged ? (newBio.isEmpty ? null : newBio) : null,
);
final updatedUser = await _usersApi.updateMe(request);
_userCache.set(updatedUser);
final updatedUser = await _userProfileService.updateMe(request);
unawaited(_userCache.setCached(updatedUser));
}
if (mounted) {
@@ -254,11 +255,10 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
Widget _buildBasicInfoSection() {
final l10n = context.l10n;
final colorScheme = Theme.of(context).colorScheme;
return AccountSectionCard(
title: l10n.settingsEditProfileBasicInfo,
backgroundColor: AppColors.white,
borderColor: AppColors.borderSecondary,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -269,14 +269,14 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: AppColors.slate700,
color: colorScheme.onSurface,
),
),
const SizedBox(height: AppSpacing.sm),
TextField(
controller: _usernameController,
onChanged: (_) => _onFieldChanged(),
style: const TextStyle(fontSize: 15, color: AppColors.slate900),
style: TextStyle(fontSize: 15, color: colorScheme.onSurface),
decoration: _buildInputDecoration(
l10n.settingsEditProfileUsernameHint,
),
@@ -287,6 +287,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
}
Widget _buildAvatarSection() {
final colorScheme = Theme.of(context).colorScheme;
final avatarUrl = _user?.avatarUrl;
final hasSelectedAvatar = _selectedAvatar != null;
@@ -300,8 +301,8 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
height: 80,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColors.surfaceSecondary,
border: Border.all(color: AppColors.borderTertiary, width: 2),
color: colorScheme.surfaceContainerLow,
border: Border.all(color: colorScheme.outlineVariant, width: 2),
image: hasSelectedAvatar
? DecorationImage(
image: FileImage(_selectedAvatar!),
@@ -315,10 +316,10 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
: null,
),
child: !hasSelectedAvatar && avatarUrl == null
? const Icon(
? Icon(
Icons.person,
size: 40,
color: AppColors.slate400,
color: colorScheme.onSurfaceVariant,
)
: null,
),
@@ -327,16 +328,16 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black.withValues(alpha: 0.4),
color: colorScheme.scrim.withValues(alpha: 0.4),
),
child: const Center(
child: Center(
child: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
AppColors.white,
colorScheme.onPrimary,
),
),
),
@@ -351,13 +352,13 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
height: 28,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColors.blue500,
border: Border.all(color: AppColors.white, width: 2),
color: colorScheme.primary,
border: Border.all(color: colorScheme.surface, width: 2),
),
child: const Icon(
child: Icon(
Icons.camera_alt,
size: 14,
color: AppColors.white,
color: colorScheme.onPrimary,
),
),
),
@@ -369,11 +370,10 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
Widget _buildBioSection() {
final l10n = context.l10n;
final colorScheme = Theme.of(context).colorScheme;
return AccountSectionCard(
title: l10n.settingsEditProfileBio,
backgroundColor: AppColors.white,
borderColor: AppColors.borderSecondary,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -382,7 +382,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: AppColors.slate700,
color: colorScheme.onSurface,
),
),
const SizedBox(height: AppSpacing.sm),
@@ -391,7 +391,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
onChanged: (_) => _onFieldChanged(),
maxLines: 4,
maxLength: 200,
style: const TextStyle(fontSize: 15, color: AppColors.slate900),
style: TextStyle(fontSize: 15, color: colorScheme.onSurface),
decoration: _buildInputDecoration(
l10n.settingsEditProfileBioHint,
).copyWith(contentPadding: const EdgeInsets.all(AppSpacing.lg)),
@@ -402,11 +402,13 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
}
InputDecoration _buildInputDecoration(String hintText) {
final colorScheme = Theme.of(context).colorScheme;
return InputDecoration(
hintText: hintText,
hintStyle: const TextStyle(fontSize: 14, color: AppColors.slate400),
hintStyle: TextStyle(fontSize: 14, color: colorScheme.onSurfaceVariant),
filled: true,
fillColor: AppColors.surfaceSecondary,
fillColor: colorScheme.surfaceContainerLow,
contentPadding: const EdgeInsets.symmetric(
horizontal: AppSpacing.lg,
vertical: AppSpacing.lg,
@@ -417,11 +419,11 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppRadius.lg),
borderSide: const BorderSide(color: AppColors.borderTertiary),
borderSide: BorderSide(color: colorScheme.outlineVariant),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppRadius.lg),
borderSide: const BorderSide(color: AppColors.blue500),
borderSide: BorderSide(color: colorScheme.primary),
),
);
}