feat: 实现日历提醒 in-app fallback 机制及通知服务重构
This commit is contained in:
@@ -1,223 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_pressable.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../../auth/presentation/bloc/auth_bloc.dart';
|
||||
import '../../../auth/presentation/bloc/auth_event.dart';
|
||||
import '../../../auth/presentation/bloc/auth_state.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../widgets/account_section_card.dart';
|
||||
import '../widgets/settings_page_scaffold.dart';
|
||||
|
||||
class AccountScreen extends StatelessWidget {
|
||||
const AccountScreen({super.key});
|
||||
|
||||
static const double _menuItemHeight = AppSpacing.xl * 2 + AppSpacing.md;
|
||||
static const double _menuItemHorizontalPadding = AppSpacing.md;
|
||||
static const double _menuIconSize = 20;
|
||||
static const double _menuChevronSize = 18;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SettingsPageScaffold(
|
||||
title: '账户',
|
||||
onBack: () => context.pop(),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [_buildListSurface(context)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildListSurface(BuildContext context) {
|
||||
return AccountSectionCard(
|
||||
backgroundColor: AppColors.white,
|
||||
borderColor: AppColors.borderSecondary,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildMenuItem(
|
||||
icon: Icons.edit,
|
||||
title: '编辑资料',
|
||||
onTap: () => context.push('/edit-profile'),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildMenuItem(
|
||||
icon: Icons.logout,
|
||||
title: '退出登录',
|
||||
titleColor: AppColors.feedbackErrorText,
|
||||
iconColor: AppColors.feedbackErrorIcon,
|
||||
trailingColor: AppColors.feedbackErrorIcon,
|
||||
onTap: () => _showLogoutSheet(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMenuItem({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required VoidCallback onTap,
|
||||
Color titleColor = AppColors.slate900,
|
||||
Color iconColor = AppColors.slate500,
|
||||
Color trailingColor = AppColors.slate400,
|
||||
}) {
|
||||
return AppPressable(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(minHeight: _menuItemHeight),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: _menuItemHorizontalPadding,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: _menuIconSize,
|
||||
child: Icon(icon, size: _menuIconSize, color: iconColor),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: titleColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
size: _menuChevronSize,
|
||||
color: trailingColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDivider() {
|
||||
return Container(
|
||||
height: 1,
|
||||
margin: const EdgeInsets.only(
|
||||
left: _menuItemHorizontalPadding + _menuIconSize + AppSpacing.md,
|
||||
right: _menuItemHorizontalPadding,
|
||||
),
|
||||
color: AppColors.borderTertiary,
|
||||
);
|
||||
}
|
||||
|
||||
void _showLogoutSheet(BuildContext context) {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
isScrollControlled: true,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
top: false,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.md,
|
||||
AppSpacing.none,
|
||||
AppSpacing.md,
|
||||
AppSpacing.md,
|
||||
),
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'退出登录',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
const Text(
|
||||
'确定退出当前账户吗?',
|
||||
style: TextStyle(fontSize: 14, color: AppColors.slate500),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
SizedBox(
|
||||
height: 52,
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
Navigator.of(sheetContext).pop();
|
||||
final authBloc = context.read<AuthBloc>();
|
||||
authBloc.add(AuthLoggedOut());
|
||||
try {
|
||||
await authBloc.stream
|
||||
.firstWhere((state) => state is AuthUnauthenticated)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
} catch (_) {
|
||||
if (context.mounted) {
|
||||
Toast.show(
|
||||
context,
|
||||
'退出失败,请稍后重试',
|
||||
type: ToastType.error,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (context.mounted) {
|
||||
context.go('/');
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.feedbackErrorIcon,
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
'确认退出',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
SizedBox(
|
||||
height: 52,
|
||||
child: AppButton(
|
||||
text: '取消',
|
||||
isOutlined: true,
|
||||
onPressed: () => Navigator.of(sheetContext).pop(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ 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 '../../../users/data/models/user_response.dart';
|
||||
import '../../../users/data/users_api.dart';
|
||||
import '../widgets/account_section_card.dart';
|
||||
@@ -22,6 +23,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
final _usernameController = TextEditingController();
|
||||
final _bioController = TextEditingController();
|
||||
final _usersApi = sl<UsersApi>();
|
||||
final _userCache = sl<SettingsUserCache>();
|
||||
|
||||
UserResponse? _user;
|
||||
bool _isLoading = true;
|
||||
@@ -35,9 +37,21 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
}
|
||||
|
||||
Future<void> _loadUser() async {
|
||||
final cached = _userCache.cachedUser;
|
||||
if (cached != null) {
|
||||
setState(() {
|
||||
_user = cached;
|
||||
_usernameController.text = cached.username;
|
||||
_bioController.text = cached.bio ?? '';
|
||||
_isLoading = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final user = await _usersApi.getMe();
|
||||
if (mounted) {
|
||||
_userCache.set(user);
|
||||
setState(() {
|
||||
_user = user;
|
||||
_usernameController.text = user.username;
|
||||
@@ -91,7 +105,8 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
username: newUsername,
|
||||
bio: newBio.isEmpty ? null : newBio,
|
||||
);
|
||||
await _usersApi.updateMe(request);
|
||||
final updatedUser = await _usersApi.updateMe(request);
|
||||
_userCache.set(updatedUser);
|
||||
|
||||
if (mounted) {
|
||||
Toast.show(context, '保存成功', type: ToastType.success);
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
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/di/injection.dart';
|
||||
import 'package:social_app/core/router/app_routes.dart';
|
||||
import 'package:social_app/core/theme/design_tokens.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';
|
||||
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/shared/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/friends/data/friends_api.dart';
|
||||
import 'package:social_app/features/settings/data/settings_api.dart';
|
||||
import 'package:social_app/features/settings/data/services/settings_user_cache.dart';
|
||||
import 'package:social_app/features/users/data/models/user_response.dart';
|
||||
import 'package:social_app/features/users/data/users_api.dart';
|
||||
import '../widgets/settings_page_scaffold.dart';
|
||||
|
||||
const settingsProfileEditButtonKey = ValueKey('settings_profile_edit_button');
|
||||
const settingsLogoutButtonKey = ValueKey('settings_logout_button');
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@@ -21,6 +33,10 @@ class SettingsScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
final UsersApi _usersApi = sl<UsersApi>();
|
||||
final FriendsApi _friendsApi = sl<FriendsApi>();
|
||||
final SettingsUserCache _userCache = sl<SettingsUserCache>();
|
||||
|
||||
UserResponse? _user;
|
||||
bool _isLoading = true;
|
||||
int _friendsCount = 0;
|
||||
@@ -29,39 +45,45 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final cachedUser = _userCache.cachedUser;
|
||||
if (cachedUser != null) {
|
||||
_user = cachedUser;
|
||||
_isLoading = false;
|
||||
}
|
||||
_loadData();
|
||||
}
|
||||
|
||||
Future<void> _loadData() async {
|
||||
try {
|
||||
final usersApi = sl<UsersApi>();
|
||||
final friendsApi = sl<FriendsApi>();
|
||||
|
||||
final results = await Future.wait([
|
||||
usersApi.getMe(),
|
||||
friendsApi.getFriends(),
|
||||
]);
|
||||
|
||||
final user = results[0] as UserResponse;
|
||||
final friends = results[1] as List<FriendResponse>;
|
||||
|
||||
final user = await _userCache.getOrLoad(_usersApi.getMe);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_user = user;
|
||||
_friendsCount = friends.length;
|
||||
_firstFriendName = friends.isNotEmpty
|
||||
? friends.first.friend.username
|
||||
: null;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
if (mounted && _user == null) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final friends = await _friendsApi.getFriends();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_friendsCount = friends.length;
|
||||
_firstFriendName = friends.isNotEmpty
|
||||
? friends.first.friend.username
|
||||
: null;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// Keep profile available even when contacts fail.
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -73,17 +95,33 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildProfileHero(),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildQuickActions(context),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildSubscriptionCard(),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildMenuCard(context),
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
_buildLogoutAction(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionLabel(String label) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProfileHero() {
|
||||
if (_isLoading) {
|
||||
return Container(
|
||||
@@ -92,7 +130,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
padding: const EdgeInsets.all(AppSpacing.xl),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xxl),
|
||||
),
|
||||
child: const Center(child: AppLoadingIndicator(size: 22)),
|
||||
);
|
||||
@@ -110,109 +148,147 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.white, Color(0xF8F9FCFF)],
|
||||
colors: [AppColors.white, AppColors.surfaceInfoLight],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
boxShadow: const [
|
||||
borderRadius: BorderRadius.circular(AppRadius.xxl),
|
||||
border: Border.all(color: AppColors.borderTertiary),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0x05000000),
|
||||
blurRadius: 12,
|
||||
offset: Offset(0, 3),
|
||||
color: AppColors.blue100.withValues(alpha: 0.35),
|
||||
blurRadius: 14,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(
|
||||
width: 64,
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.blue100, AppColors.blue50],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color.fromRGBO(
|
||||
AppColors.blue400.r.toInt(),
|
||||
AppColors.blue400.g.toInt(),
|
||||
AppColors.blue400.b.toInt(),
|
||||
0.2,
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 64,
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.blue100, AppColors.blue50],
|
||||
),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(Icons.person, size: 28, color: AppColors.blue600),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
username,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color.fromRGBO(
|
||||
AppColors.blue400.r.toInt(),
|
||||
AppColors.blue400.g.toInt(),
|
||||
AppColors.blue400.b.toInt(),
|
||||
0.2,
|
||||
),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 5,
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person,
|
||||
size: 28,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
username,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.blue50,
|
||||
AppColors.surfaceInfoLight,
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.borderQuaternary),
|
||||
),
|
||||
child: const Text(
|
||||
'Free',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
phone,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
phone,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
AppPressable(
|
||||
key: settingsProfileEditButtonKey,
|
||||
onTap: _onTapEditProfile,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
child: SizedBox(
|
||||
width: AppSpacing.xl * 2,
|
||||
height: AppSpacing.xl * 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.edit,
|
||||
size: 14,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Container(
|
||||
width: 12,
|
||||
height: 1.5,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.slate400,
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppRadius.full,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_buildFreeBadge(),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFreeBadge() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [AppColors.blue50, AppColors.surfaceInfoLight],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.borderQuaternary),
|
||||
),
|
||||
child: const Text(
|
||||
'Free',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _buildFriendsSubtitle() {
|
||||
if (_friendsCount == 0) {
|
||||
return '暂无联系人';
|
||||
@@ -232,17 +308,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
iconColor: AppColors.blue500,
|
||||
title: '联系人',
|
||||
subtitle: _buildFriendsSubtitle(),
|
||||
onTap: () => context.push('/contacts'),
|
||||
onTap: () => context.push(AppRoutes.contactsList),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: _buildActionCard(
|
||||
icon: Icons.auto_awesome,
|
||||
iconColor: const Color(0xFF8B5CF6),
|
||||
iconColor: AppColors.violet500,
|
||||
title: '周期计划',
|
||||
subtitle: '已启用:会议提醒',
|
||||
onTap: () => context.push('/settings/features'),
|
||||
onTap: () => context.push(AppRoutes.settingsFeatures),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -256,19 +332,21 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
return AppPressable(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(minHeight: 136),
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
boxShadow: const [
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0x04000000),
|
||||
blurRadius: 6,
|
||||
offset: Offset(0, 1),
|
||||
color: AppColors.slate200.withValues(alpha: 0.45),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -323,15 +401,15 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.white, const Color(0xFFFAFBFF)],
|
||||
colors: [AppColors.white, AppColors.surfaceInfoLight],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
boxShadow: const [
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderTertiary),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0x03000000),
|
||||
blurRadius: 6,
|
||||
offset: Offset(0, 1),
|
||||
color: AppColors.slate200.withValues(alpha: 0.4),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -419,7 +497,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: AppColors.borderSecondary),
|
||||
),
|
||||
child: Column(
|
||||
@@ -433,13 +511,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
_buildMenuItem(
|
||||
icon: Icons.bookmark,
|
||||
title: '我的记忆',
|
||||
onTap: () => context.push('/settings/memory'),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildMenuItem(
|
||||
icon: Icons.person,
|
||||
title: '我的账户',
|
||||
onTap: () => context.push('/settings/account'),
|
||||
onTap: () => context.push(AppRoutes.settingsMemory),
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildMenuItem(
|
||||
@@ -459,9 +531,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
String? trailing,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
return AppPressable(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
child: Container(
|
||||
height: 56,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
@@ -515,6 +587,45 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onTapEditProfile() async {
|
||||
final changed = await context.push<bool>(AppRoutes.settingsEditProfile);
|
||||
if (changed == true && mounted) {
|
||||
final cached = _userCache.cachedUser;
|
||||
if (cached != null) {
|
||||
setState(() {
|
||||
_user = cached;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onTapLogout() async {
|
||||
final confirmed = await showDestructiveActionSheet(
|
||||
context,
|
||||
title: '退出登录',
|
||||
message: '确定退出当前账户吗?',
|
||||
confirmText: '确认退出',
|
||||
);
|
||||
if (!confirmed || !mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
_userCache.invalidate();
|
||||
final authBloc = context.read<AuthBloc>();
|
||||
authBloc.add(AuthLoggedOut());
|
||||
try {
|
||||
await authBloc.stream
|
||||
.firstWhere((state) => state is AuthUnauthenticated)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
Toast.show(context, '退出失败,请稍后重试', type: ToastType.error);
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
context.go(AppRoutes.authLogin);
|
||||
}
|
||||
|
||||
Future<void> _checkForUpdates() async {
|
||||
try {
|
||||
final settingsApi = sl<SettingsApi>();
|
||||
@@ -566,4 +677,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
Toast.show(context, '检查更新失败', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildLogoutAction() {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: AppButton(
|
||||
key: settingsLogoutButtonKey,
|
||||
text: '退出登录',
|
||||
isOutlined: true,
|
||||
onPressed: () => _onTapLogout(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user