feat: 重构 memory 系统,支持 user memory 和 work memory 分离

This commit is contained in:
qzl
2026-03-23 14:25:47 +08:00
parent 3aacc756db
commit 6be616f108
70 changed files with 7031 additions and 431 deletions
@@ -1,9 +1,15 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../../core/theme/design_tokens.dart';
import '../../../../shared/widgets/app_toggle_switch.dart';
import '../../data/services/memory_service.dart';
import 'package:social_app/core/di/injection.dart';
import 'package:social_app/core/theme/design_tokens.dart';
import 'package:social_app/core/router/app_routes.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/toast/toast.dart';
import 'package:social_app/shared/widgets/toast/toast_type.dart';
import '../widgets/settings_page_scaffold.dart';
import '../../data/models/memory_models.dart';
import '../../data/services/memory_service.dart';
class MemoryScreen extends StatefulWidget {
const MemoryScreen({super.key});
@@ -13,14 +19,38 @@ class MemoryScreen extends StatefulWidget {
}
class _MemoryScreenState extends State<MemoryScreen> {
bool _memoryEnabled = true;
final MemoryService _memoryService = MemoryService();
late List<MemoryItemModel> _memoryItems;
final MemoryService _memoryService = sl<MemoryService>();
MemoryListResponse? _memoryData;
bool _isLoading = true;
String? _error;
@override
void initState() {
super.initState();
_memoryItems = _memoryService.getMemoryItems();
_loadMemories();
}
Future<void> _loadMemories() async {
if (!mounted) return;
setState(() {
_isLoading = true;
_error = null;
});
try {
final data = await _memoryService.getAllMemories();
if (!mounted) return;
setState(() {
_memoryData = data;
_isLoading = false;
});
} catch (e) {
if (!mounted) return;
setState(() {
_error = '加载失败,请重试';
_isLoading = false;
});
}
}
@override
@@ -28,18 +58,22 @@ class _MemoryScreenState extends State<MemoryScreen> {
return SettingsPageScaffold(
title: '我的记忆',
onBack: () => context.pop(),
footer: _buildFooter(),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildToggleCard(),
if (_memoryItems.isNotEmpty) ...[
const SizedBox(height: 14),
_buildListTitle(),
const SizedBox(height: 8),
_buildMemoryList(),
const SizedBox(height: AppSpacing.lg),
if (_isLoading) ...[
const SizedBox(height: AppSpacing.xxl),
_buildLoadingState(),
] else if (_error != null) ...[
const SizedBox(height: AppSpacing.xxl),
_buildErrorState(),
] else ...[
const SizedBox(height: AppSpacing.sm),
_buildMemoryCards(),
],
const SizedBox(height: 20),
_buildManageButton(),
],
),
);
@@ -47,42 +81,122 @@ class _MemoryScreenState extends State<MemoryScreen> {
Widget _buildToggleCard() {
return Container(
padding: const EdgeInsets.all(14),
padding: const EdgeInsets.all(AppSpacing.lg),
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColors.borderSecondary),
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.white, AppColors.surfaceInfoLight],
),
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(color: AppColors.borderTertiary),
boxShadow: [
BoxShadow(
color: AppColors.blue100.withValues(alpha: 0.35),
blurRadius: 14,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'启用记忆',
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.blue100, AppColors.blue50],
),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: AppColors.blue200.withValues(alpha: 0.45),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Icon(
Icons.auto_awesome,
size: 22,
color: AppColors.blue600,
),
),
const SizedBox(width: AppSpacing.md),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'智能记忆',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.slate900,
),
),
const SizedBox(height: 2),
Text(
'持续学习你的偏好和习惯',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
),
),
],
),
),
],
),
);
}
Widget _buildLoadingState() {
return Center(
child: Container(
padding: const EdgeInsets.all(AppSpacing.xxl),
child: const AppLoadingIndicator(size: 32),
),
);
}
Widget _buildErrorState() {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline, size: 48, color: AppColors.slate300),
const SizedBox(height: AppSpacing.md),
Text(
_error ?? '加载失败',
style: TextStyle(fontSize: 14, color: AppColors.slate500),
),
const SizedBox(height: AppSpacing.lg),
AppPressable(
onTap: _loadMemories,
borderRadius: BorderRadius.circular(AppRadius.md),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.lg,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColors.blue50,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.blue100),
),
child: const Text(
'重新加载',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.slate900,
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.blue600,
),
),
_buildToggle(_memoryEnabled, (v) {
setState(() => _memoryEnabled = v);
}),
],
),
const SizedBox(height: 10),
const Align(
alignment: Alignment.centerLeft,
child: Text(
'开启后,将持续记录并更新你的长期偏好',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.normal,
color: Color(0xFF71839F),
),
),
),
],
@@ -90,122 +204,318 @@ class _MemoryScreenState extends State<MemoryScreen> {
);
}
Widget _buildListTitle() {
return const Text(
'记忆条目',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: AppColors.slate500,
Widget _buildMemoryCards() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildSectionLabel('用户记忆'),
const SizedBox(height: AppSpacing.sm),
_buildUserMemoryCard(),
const SizedBox(height: AppSpacing.md),
_buildSectionLabel('工作记忆'),
const SizedBox(height: AppSpacing.sm),
_buildWorkMemoryCard(),
],
);
}
Widget _buildSectionLabel(String label) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
child: Text(
label,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: AppColors.slate500,
),
),
);
}
Widget _buildMemoryList() {
return Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (int i = 0; i < _memoryItems.length; i++) ...[
_buildMemoryItem(_memoryItems[i]),
if (i < _memoryItems.length - 1) const SizedBox(height: 10),
],
],
),
);
}
Widget _buildUserMemoryCard() {
final userMemory = _memoryData?.userMemory;
final hasData = userMemory != null;
Widget _buildMemoryItem(MemoryItemModel item) {
return GestureDetector(
onTap: () {},
return AppPressable(
onTap: () => context.push(AppRoutes.settingsMemoryUser),
borderRadius: BorderRadius.circular(AppRadius.xl),
child: Container(
height: 74,
padding: const EdgeInsets.all(12),
padding: const EdgeInsets.all(AppSpacing.lg),
decoration: BoxDecoration(
color: AppColors.surfaceTertiary,
borderRadius: BorderRadius.circular(12),
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.white, AppColors.surfaceInfoLight],
),
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(color: AppColors.borderTertiary),
boxShadow: [
BoxShadow(
color: AppColors.slate200.withValues(alpha: 0.45),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
AppColors.blue100.withValues(alpha: 0.8),
AppColors.blue50.withValues(alpha: 0.8),
],
),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.person,
size: 20,
color: AppColors.blue600,
),
),
const SizedBox(width: AppSpacing.md),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'个人偏好',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.slate900,
),
),
const SizedBox(height: 2),
Text(
hasData ? userMemory.summary : '暂无信息',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
Icon(Icons.chevron_right, size: 20, color: AppColors.slate400),
],
),
if (hasData) ...[
const SizedBox(height: AppSpacing.md),
_buildMemoryStatsRow(
icons: [
Icons.people_outline,
Icons.place_outlined,
Icons.interests_outlined,
Icons.schedule_outlined,
],
values: [
'${userMemory.people.length}',
'${userMemory.places.length}',
'${userMemory.interests.length}',
'${userMemory.recurringRoutines.length}',
],
labels: ['联系人', '地点', '兴趣', '日程'],
),
],
],
),
),
);
}
Widget _buildWorkMemoryCard() {
final workMemory = _memoryData?.workMemory;
final hasData = workMemory != null;
return AppPressable(
onTap: () => context.push(AppRoutes.settingsMemoryWork),
borderRadius: BorderRadius.circular(AppRadius.xl),
child: Container(
padding: const EdgeInsets.all(AppSpacing.lg),
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColors.white, AppColors.surfaceTertiary],
),
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(color: AppColors.borderSecondary),
boxShadow: [
BoxShadow(
color: AppColors.slate200.withValues(alpha: 0.4),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
AppColors.violet500.withValues(alpha: 0.15),
AppColors.violet500.withValues(alpha: 0.05),
],
),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.work_outline,
size: 20,
color: AppColors.violet600,
),
),
const SizedBox(width: AppSpacing.md),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'工作Profile',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.slate900,
),
),
const SizedBox(height: 2),
Text(
hasData ? workMemory.summary : '暂无信息',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
Icon(Icons.chevron_right, size: 20, color: AppColors.slate400),
],
),
if (hasData) ...[
const SizedBox(height: AppSpacing.md),
_buildMemoryStatsRow(
icons: [
Icons.psychology_outlined,
Icons.build_outlined,
Icons.folder_outlined,
Icons.groups_outlined,
],
values: [
'${workMemory.expertise.length}',
'${workMemory.preferredTools.length}',
'${workMemory.currentProjects.length}',
'${workMemory.teamMembers.length}',
],
labels: ['专长', '工具', '项目', '团队'],
),
],
],
),
),
);
}
Widget _buildMemoryStatsRow({
required List<IconData> icons,
required List<String> values,
required List<String> labels,
}) {
return Row(
children: List.generate(icons.length, (index) {
return Expanded(
child: Container(
padding: const EdgeInsets.symmetric(vertical: AppSpacing.sm),
margin: EdgeInsets.only(
right: index < icons.length - 1 ? AppSpacing.sm : 0,
),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Column(
children: [
Icon(icons[index], size: 16, color: AppColors.slate400),
const SizedBox(height: 4),
Text(
values[index],
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: AppColors.slate700,
),
),
const SizedBox(height: 2),
Text(
labels[index],
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w500,
color: AppColors.slate400,
),
),
],
),
),
);
}),
);
}
Widget? _buildFooter() {
return AppPressable(
onTap: () {
Toast.show(context, '记忆会随着你的使用自动完善', type: ToastType.info);
},
borderRadius: BorderRadius.circular(AppRadius.lg),
child: Container(
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceInfoLight,
borderRadius: BorderRadius.circular(AppRadius.lg),
border: Border.all(color: AppColors.borderQuaternary),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 32,
height: 32,
decoration: BoxDecoration(
color: AppColors.surfaceInfo,
borderRadius: BorderRadius.circular(10),
Icon(Icons.info_outline, size: 16, color: AppColors.blue500),
const SizedBox(width: AppSpacing.sm),
const Text(
'点击卡片查看或编辑详情',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: AppColors.blue600,
),
child: Icon(item.icon, size: 16, color: AppColors.blue500),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
item.title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.slate900,
),
),
const SizedBox(height: 4),
Text(
item.subtitle,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.normal,
color: AppColors.slate500,
),
),
],
),
),
const Icon(
Icons.chevron_right,
size: 16,
color: AppColors.slate400,
),
],
),
),
);
}
Widget _buildManageButton() {
return GestureDetector(
onTap: () {},
child: Container(
height: 44,
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColors.borderSecondary),
),
child: const Center(
child: Text(
'管理记忆条目',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.slate700,
),
),
),
),
);
}
Widget _buildToggle(bool value, ValueChanged<bool> onChanged) {
return AppToggleSwitch(value: value, onChanged: onChanged);
}
}
@@ -0,0 +1,942 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:social_app/core/di/injection.dart';
import 'package:social_app/core/theme/design_tokens.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/toast/toast.dart';
import 'package:social_app/shared/widgets/toast/toast_type.dart';
import '../widgets/settings_page_scaffold.dart';
import '../../data/models/memory_models.dart';
import '../../data/services/memory_service.dart';
class UserMemoryDetailScreen extends StatefulWidget {
const UserMemoryDetailScreen({super.key});
@override
State<UserMemoryDetailScreen> createState() => _UserMemoryDetailScreenState();
}
class _UserMemoryDetailScreenState extends State<UserMemoryDetailScreen> {
final MemoryService _memoryService = sl<MemoryService>();
UserMemoryContent? _memory;
bool _isLoading = true;
bool _isSaving = false;
String? _error;
bool _hasChanges = false;
@override
void initState() {
super.initState();
_loadMemory();
}
Future<void> _loadMemory() async {
if (!mounted) return;
setState(() {
_isLoading = true;
_error = null;
});
try {
final memory = await _memoryService.getUserMemory();
if (!mounted) return;
setState(() {
_memory = memory;
_isLoading = false;
});
} catch (e) {
if (!mounted) return;
setState(() {
_error = '加载失败';
_isLoading = false;
});
}
}
Future<void> _saveMemory() async {
if (_memory == null || !_hasChanges) return;
if (!mounted) return;
setState(() {
_isSaving = true;
});
try {
await _memoryService.updateUserMemory(_memory!);
if (!mounted) return;
setState(() {
_isSaving = false;
_hasChanges = false;
});
Toast.show(context, '保存成功', type: ToastType.success);
} catch (e) {
if (!mounted) return;
setState(() {
_isSaving = false;
});
Toast.show(context, '保存失败', type: ToastType.error);
}
}
void _updateMemory(UserMemoryContent newMemory) {
setState(() {
_memory = newMemory;
_hasChanges = true;
});
}
@override
Widget build(BuildContext context) {
return SettingsPageScaffold(
title: '个人偏好',
onBack: () => context.pop(),
footer: _hasChanges ? _buildSaveButton() : null,
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (_isLoading) ...[
const SizedBox(height: AppSpacing.xxl * 2),
_buildLoadingState(),
] else if (_error != null) ...[
const SizedBox(height: AppSpacing.xxl * 2),
_buildErrorState(),
] else if (_memory != null) ...[
_buildContent(),
] else ...[
const SizedBox(height: AppSpacing.xxl * 2),
_buildEmptyState(),
],
],
),
);
}
Widget _buildLoadingState() {
return const Center(child: AppLoadingIndicator(size: 32));
}
Widget _buildErrorState() {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline, size: 48, color: AppColors.slate300),
const SizedBox(height: AppSpacing.md),
Text(_error ?? '加载失败', style: TextStyle(color: AppColors.slate500)),
const SizedBox(height: AppSpacing.lg),
AppPressable(
onTap: _loadMemory,
borderRadius: BorderRadius.circular(AppRadius.md),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.lg,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColors.blue50,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.blue100),
),
child: const Text(
'重新加载',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.blue600,
),
),
),
),
],
),
);
}
Widget _buildEmptyState() {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.person_off_outlined, size: 48, color: AppColors.slate300),
const SizedBox(height: AppSpacing.md),
Text('暂无个人偏好信息', style: TextStyle(color: AppColors.slate500)),
],
),
);
}
Widget _buildSaveButton() {
return SizedBox(
width: double.infinity,
height: 52,
child: AppPressable(
onTap: _isSaving ? null : _saveMemory,
borderRadius: BorderRadius.circular(AppRadius.lg),
child: Container(
height: 52,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [AppColors.blue500, AppColors.blue600],
),
borderRadius: BorderRadius.circular(AppRadius.lg),
boxShadow: [
BoxShadow(
color: const Color(0x4D60A5FA),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Center(
child: _isSaving
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
AppColors.white,
),
),
)
: const Text(
'保存更改',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.white,
),
),
),
),
),
);
}
Widget _buildContent() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildBasicInfoSection(),
const SizedBox(height: AppSpacing.lg),
_buildPeopleSection(),
const SizedBox(height: AppSpacing.lg),
_buildPlacesSection(),
const SizedBox(height: AppSpacing.lg),
_buildPreferencesSection(),
const SizedBox(height: AppSpacing.lg),
_buildInterestsSection(),
const SizedBox(height: AppSpacing.lg),
_buildAvoidTopicsSection(),
const SizedBox(height: AppSpacing.lg),
_buildRecurringRoutinesSection(),
const SizedBox(height: AppSpacing.xxl),
],
);
}
Widget _buildBasicInfoSection() {
return _buildSection(
title: '基本信息',
icon: Icons.person_outline,
children: [
_buildEditField(
label: '职业',
value: _memory?.occupation,
onChanged: (value) =>
_updateMemory(_memory!.copyWith(occupation: value)),
),
_buildEditField(
label: '时区',
value: _memory?.timezone,
onChanged: (value) =>
_updateMemory(_memory!.copyWith(timezone: value)),
),
_buildEditField(
label: '主要语言',
value: _memory?.primaryLanguage,
onChanged: (value) =>
_updateMemory(_memory!.copyWith(primaryLanguage: value)),
),
],
);
}
Widget _buildPeopleSection() {
return _buildSection(
title: '联系人',
icon: Icons.people_outline,
count: _memory?.people.length ?? 0,
children: [
if (_memory?.people.isEmpty ?? true)
_buildEmptySection('暂无联系人')
else
..._memory!.people.asMap().entries.map((entry) {
final index = entry.key;
final person = entry.value;
return _buildPersonItem(person, index);
}),
const SizedBox(height: AppSpacing.sm),
_buildAddButton('添加联系人', () {
final newPeople = List<Person>.from(_memory!.people)
..add(Person(name: '新联系人'));
_updateMemory(_memory!.copyWith(people: newPeople));
}),
],
);
}
Widget _buildPersonItem(Person person, int index) {
return Container(
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: _buildEditField(
label: '姓名',
value: person.name,
onChanged: (value) {
final newPeople = List<Person>.from(_memory!.people);
newPeople[index] = person.copyWith(name: value);
_updateMemory(_memory!.copyWith(people: newPeople));
},
),
),
AppPressable(
onTap: () {
final newPeople = List<Person>.from(_memory!.people)
..removeAt(index);
_updateMemory(_memory!.copyWith(people: newPeople));
},
borderRadius: BorderRadius.circular(AppRadius.sm),
child: Container(
padding: const EdgeInsets.all(AppSpacing.xs),
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
),
),
],
),
const SizedBox(height: AppSpacing.sm),
Row(
children: [
Expanded(
child: _buildEditField(
label: '关系',
value: person.relationship,
onChanged: (value) {
final newPeople = List<Person>.from(_memory!.people);
newPeople[index] = person.copyWith(relationship: value);
_updateMemory(_memory!.copyWith(people: newPeople));
},
),
),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: _buildEditField(
label: '角色',
value: person.role,
onChanged: (value) {
final newPeople = List<Person>.from(_memory!.people);
newPeople[index] = person.copyWith(role: value);
_updateMemory(_memory!.copyWith(people: newPeople));
},
),
),
],
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '联系方式',
value: person.preferredContactChannel,
onChanged: (value) {
final newPeople = List<Person>.from(_memory!.people);
newPeople[index] = person.copyWith(
preferredContactChannel: value,
);
_updateMemory(_memory!.copyWith(people: newPeople));
},
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '备注',
value: person.notes,
onChanged: (value) {
final newPeople = List<Person>.from(_memory!.people);
newPeople[index] = person.copyWith(notes: value);
_updateMemory(_memory!.copyWith(people: newPeople));
},
),
],
),
);
}
Widget _buildPlacesSection() {
return _buildSection(
title: '地点',
icon: Icons.place_outlined,
count: _memory?.places.length ?? 0,
children: [
if (_memory?.places.isEmpty ?? true)
_buildEmptySection('暂无地点')
else
..._memory!.places.asMap().entries.map((entry) {
final index = entry.key;
final place = entry.value;
return _buildPlaceItem(place, index);
}),
const SizedBox(height: AppSpacing.sm),
_buildAddButton('添加地点', () {
final newPlaces = List<Place>.from(_memory!.places)
..add(Place(name: '新地点'));
_updateMemory(_memory!.copyWith(places: newPlaces));
}),
],
);
}
Widget _buildPlaceItem(Place place, int index) {
return Container(
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: _buildEditField(
label: '名称',
value: place.name,
onChanged: (value) {
final newPlaces = List<Place>.from(_memory!.places);
newPlaces[index] = place.copyWith(name: value);
_updateMemory(_memory!.copyWith(places: newPlaces));
},
),
),
AppPressable(
onTap: () {
final newPlaces = List<Place>.from(_memory!.places)
..removeAt(index);
_updateMemory(_memory!.copyWith(places: newPlaces));
},
borderRadius: BorderRadius.circular(AppRadius.sm),
child: Container(
padding: const EdgeInsets.all(AppSpacing.xs),
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
),
),
],
),
const SizedBox(height: AppSpacing.sm),
Row(
children: [
Expanded(
child: _buildEditField(
label: '类别',
value: place.category,
onChanged: (value) {
final newPlaces = List<Place>.from(_memory!.places);
newPlaces[index] = place.copyWith(category: value);
_updateMemory(_memory!.copyWith(places: newPlaces));
},
),
),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: _buildEditField(
label: '偏好',
value: place.preference,
onChanged: (value) {
final newPlaces = List<Place>.from(_memory!.places);
newPlaces[index] = place.copyWith(preference: value);
_updateMemory(_memory!.copyWith(places: newPlaces));
},
),
),
],
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '地址',
value: place.address,
onChanged: (value) {
final newPlaces = List<Place>.from(_memory!.places);
newPlaces[index] = place.copyWith(address: value);
_updateMemory(_memory!.copyWith(places: newPlaces));
},
),
],
),
);
}
Widget _buildPreferencesSection() {
final prefs = _memory!.preferences;
return _buildSection(
title: '偏好设置',
icon: Icons.settings_outlined,
children: [
_buildEditField(
label: '沟通风格',
value: prefs.communicationStyle,
onChanged: (value) {
_updateMemory(
_memory!.copyWith(
preferences: prefs.copyWith(communicationStyle: value),
),
);
},
),
_buildEditField(
label: '位置偏好',
value: prefs.locationPreference,
onChanged: (value) {
_updateMemory(
_memory!.copyWith(
preferences: prefs.copyWith(locationPreference: value),
),
);
},
),
_buildEditField(
label: '工作生活方式',
value: prefs.workLifestyle,
onChanged: (value) {
_updateMemory(
_memory!.copyWith(
preferences: prefs.copyWith(workLifestyle: value),
),
);
},
),
],
);
}
Widget _buildInterestsSection() {
return _buildSection(
title: '兴趣',
icon: Icons.interests_outlined,
children: [
_buildTagsSection(
tags: _memory?.interests ?? [],
onAdd: (tag) {
_updateMemory(
_memory!.copyWith(interests: [..._memory!.interests, tag]),
);
},
onRemove: (index) {
final newInterests = List<String>.from(_memory!.interests)
..removeAt(index);
_updateMemory(_memory!.copyWith(interests: newInterests));
},
),
],
);
}
Widget _buildAvoidTopicsSection() {
return _buildSection(
title: '回避话题',
icon: Icons.not_interested_outlined,
children: [
_buildTagsSection(
tags: _memory?.avoidTopics ?? [],
onAdd: (tag) {
_updateMemory(
_memory!.copyWith(avoidTopics: [..._memory!.avoidTopics, tag]),
);
},
onRemove: (index) {
final newTopics = List<String>.from(_memory!.avoidTopics)
..removeAt(index);
_updateMemory(_memory!.copyWith(avoidTopics: newTopics));
},
),
],
);
}
Widget _buildRecurringRoutinesSection() {
return _buildSection(
title: '周期习惯',
icon: Icons.schedule_outlined,
count: _memory?.recurringRoutines.length ?? 0,
children: [
if (_memory?.recurringRoutines.isEmpty ?? true)
_buildEmptySection('暂无周期习惯')
else
..._memory!.recurringRoutines.asMap().entries.map((entry) {
final index = entry.key;
final routine = entry.value;
return _buildRoutineItem(routine, index);
}),
const SizedBox(height: AppSpacing.sm),
_buildAddButton('添加习惯', () {
final newRoutines = List<RecurringRoutine>.from(
_memory!.recurringRoutines,
)..add(RecurringRoutine(name: '新习惯'));
_updateMemory(_memory!.copyWith(recurringRoutines: newRoutines));
}),
],
);
}
Widget _buildRoutineItem(RecurringRoutine routine, int index) {
return Container(
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: _buildEditField(
label: '名称',
value: routine.name,
onChanged: (value) {
final newRoutines = List<RecurringRoutine>.from(
_memory!.recurringRoutines,
);
newRoutines[index] = routine.copyWith(name: value);
_updateMemory(
_memory!.copyWith(recurringRoutines: newRoutines),
);
},
),
),
AppPressable(
onTap: () {
final newRoutines = List<RecurringRoutine>.from(
_memory!.recurringRoutines,
)..removeAt(index);
_updateMemory(
_memory!.copyWith(recurringRoutines: newRoutines),
);
},
borderRadius: BorderRadius.circular(AppRadius.sm),
child: Container(
padding: const EdgeInsets.all(AppSpacing.xs),
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
),
),
],
),
const SizedBox(height: AppSpacing.sm),
Row(
children: [
Expanded(
child: _buildEditField(
label: '描述',
value: routine.description,
onChanged: (value) {
final newRoutines = List<RecurringRoutine>.from(
_memory!.recurringRoutines,
);
newRoutines[index] = routine.copyWith(description: value);
_updateMemory(
_memory!.copyWith(recurringRoutines: newRoutines),
);
},
),
),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: _buildEditField(
label: '周期',
value: routine.cadence,
onChanged: (value) {
final newRoutines = List<RecurringRoutine>.from(
_memory!.recurringRoutines,
);
newRoutines[index] = routine.copyWith(cadence: value);
_updateMemory(
_memory!.copyWith(recurringRoutines: newRoutines),
);
},
),
),
],
),
],
),
);
}
Widget _buildSection({
required String title,
required IconData icon,
int? count,
required List<Widget> children,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, size: 18, color: AppColors.blue500),
const SizedBox(width: AppSpacing.sm),
Text(
title,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: AppColors.slate800,
),
),
if (count != null) ...[
const SizedBox(width: AppSpacing.xs),
Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.sm,
vertical: 2,
),
decoration: BoxDecoration(
color: AppColors.blue50,
borderRadius: BorderRadius.circular(AppRadius.full),
),
child: Text(
'$count',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: AppColors.blue600,
),
),
),
],
],
),
const SizedBox(height: AppSpacing.md),
...children,
],
);
}
Widget _buildEditField({
required String label,
String? value,
required ValueChanged<String> onChanged,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
),
),
const SizedBox(height: AppSpacing.xs),
Container(
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: TextFormField(
initialValue: value,
onChanged: onChanged,
style: const TextStyle(fontSize: 14, color: AppColors.slate800),
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
border: InputBorder.none,
hintText: '输入$label',
hintStyle: TextStyle(color: AppColors.slate400, fontSize: 14),
),
),
),
],
);
}
Widget _buildEmptySection(String message) {
return Container(
padding: const EdgeInsets.all(AppSpacing.lg),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: Center(
child: Text(
message,
style: TextStyle(fontSize: 14, color: AppColors.slate400),
),
),
);
}
Widget _buildTagsSection({
required List<String> tags,
required ValueChanged<String> onAdd,
required ValueChanged<int> onRemove,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: AppSpacing.sm,
runSpacing: AppSpacing.sm,
children: [
...tags.asMap().entries.map((entry) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColors.blue50,
borderRadius: BorderRadius.circular(AppRadius.full),
border: Border.all(color: AppColors.blue100),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
entry.value,
style: const TextStyle(
fontSize: 13,
color: AppColors.blue600,
),
),
const SizedBox(width: AppSpacing.xs),
AppPressable(
onTap: () => onRemove(entry.key),
borderRadius: BorderRadius.circular(AppRadius.full),
child: Icon(
Icons.close,
size: 14,
color: AppColors.blue400,
),
),
],
),
);
}),
AppPressable(
onTap: () => _showAddTagDialog(onAdd),
borderRadius: BorderRadius.circular(AppRadius.full),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.full),
border: Border.all(
color: AppColors.borderSecondary,
style: BorderStyle.solid,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.add, size: 14, color: AppColors.slate500),
const SizedBox(width: AppSpacing.xs),
Text(
'添加',
style: TextStyle(fontSize: 13, color: AppColors.slate500),
),
],
),
),
),
],
),
],
);
}
void _showAddTagDialog(ValueChanged<String> onAdd) {
final controller = TextEditingController();
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('添加'),
content: TextField(
controller: controller,
autofocus: true,
decoration: const InputDecoration(hintText: '输入内容'),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
TextButton(
onPressed: () {
if (controller.text.isNotEmpty) {
onAdd(controller.text);
}
Navigator.pop(context);
},
child: const Text('添加'),
),
],
),
);
}
Widget _buildAddButton(String text, VoidCallback onTap) {
return AppPressable(
onTap: onTap,
borderRadius: BorderRadius.circular(AppRadius.md),
child: Container(
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(
color: AppColors.borderSecondary,
style: BorderStyle.solid,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add, size: 18, color: AppColors.blue500),
const SizedBox(width: AppSpacing.xs),
Text(
text,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.blue600,
),
),
],
),
),
);
}
}
@@ -0,0 +1,889 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:social_app/core/di/injection.dart';
import 'package:social_app/core/theme/design_tokens.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/toast/toast.dart';
import 'package:social_app/shared/widgets/toast/toast_type.dart';
import '../widgets/settings_page_scaffold.dart';
import '../../data/models/memory_models.dart';
import '../../data/services/memory_service.dart';
class WorkMemoryDetailScreen extends StatefulWidget {
const WorkMemoryDetailScreen({super.key});
@override
State<WorkMemoryDetailScreen> createState() => _WorkMemoryDetailScreenState();
}
class _WorkMemoryDetailScreenState extends State<WorkMemoryDetailScreen> {
final MemoryService _memoryService = sl<MemoryService>();
WorkProfileContent? _memory;
bool _isLoading = true;
bool _isSaving = false;
String? _error;
bool _hasChanges = false;
@override
void initState() {
super.initState();
_loadMemory();
}
Future<void> _loadMemory() async {
if (!mounted) return;
setState(() {
_isLoading = true;
_error = null;
});
try {
final memory = await _memoryService.getWorkMemory();
if (!mounted) return;
setState(() {
_memory = memory;
_isLoading = false;
});
} catch (e) {
if (!mounted) return;
setState(() {
_error = '加载失败';
_isLoading = false;
});
}
}
Future<void> _saveMemory() async {
if (_memory == null || !_hasChanges) return;
if (!mounted) return;
setState(() {
_isSaving = true;
});
try {
await _memoryService.updateWorkMemory(_memory!);
if (!mounted) return;
setState(() {
_isSaving = false;
_hasChanges = false;
});
Toast.show(context, '保存成功', type: ToastType.success);
} catch (e) {
if (!mounted) return;
setState(() {
_isSaving = false;
});
Toast.show(context, '保存失败', type: ToastType.error);
}
}
void _updateMemory(WorkProfileContent newMemory) {
setState(() {
_memory = newMemory;
_hasChanges = true;
});
}
@override
Widget build(BuildContext context) {
return SettingsPageScaffold(
title: '工作Profile',
onBack: () => context.pop(),
footer: _hasChanges ? _buildSaveButton() : null,
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (_isLoading) ...[
const SizedBox(height: AppSpacing.xxl * 2),
_buildLoadingState(),
] else if (_error != null) ...[
const SizedBox(height: AppSpacing.xxl * 2),
_buildErrorState(),
] else if (_memory != null) ...[
_buildContent(),
] else ...[
const SizedBox(height: AppSpacing.xxl * 2),
_buildEmptyState(),
],
],
),
);
}
Widget _buildLoadingState() {
return const Center(child: AppLoadingIndicator(size: 32));
}
Widget _buildErrorState() {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline, size: 48, color: AppColors.slate300),
const SizedBox(height: AppSpacing.md),
Text(_error ?? '加载失败', style: TextStyle(color: AppColors.slate500)),
const SizedBox(height: AppSpacing.lg),
AppPressable(
onTap: _loadMemory,
borderRadius: BorderRadius.circular(AppRadius.md),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.lg,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColors.blue50,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.blue100),
),
child: const Text(
'重新加载',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.blue600,
),
),
),
),
],
),
);
}
Widget _buildEmptyState() {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.work_off_outlined, size: 48, color: AppColors.slate300),
const SizedBox(height: AppSpacing.md),
Text('暂无工作信息', style: TextStyle(color: AppColors.slate500)),
],
),
);
}
Widget _buildSaveButton() {
return SizedBox(
width: double.infinity,
height: 52,
child: AppPressable(
onTap: _isSaving ? null : _saveMemory,
borderRadius: BorderRadius.circular(AppRadius.lg),
child: Container(
height: 52,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [AppColors.blue500, AppColors.blue600],
),
borderRadius: BorderRadius.circular(AppRadius.lg),
boxShadow: [
BoxShadow(
color: const Color(0x4D60A5FA),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Center(
child: _isSaving
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
AppColors.white,
),
),
)
: const Text(
'保存更改',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.white,
),
),
),
),
),
);
}
Widget _buildContent() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildBasicInfoSection(),
const SizedBox(height: AppSpacing.lg),
_buildExpertiseSection(),
const SizedBox(height: AppSpacing.lg),
_buildPreferredToolsSection(),
const SizedBox(height: AppSpacing.lg),
_buildProjectsSection(),
const SizedBox(height: AppSpacing.lg),
_buildTeamMembersSection(),
const SizedBox(height: AppSpacing.lg),
_buildWorkHabitsSection(),
const SizedBox(height: AppSpacing.lg),
_buildTeamContextSection(),
const SizedBox(height: AppSpacing.lg),
_buildWorkRulesSection(),
const SizedBox(height: AppSpacing.xxl),
],
);
}
Widget _buildBasicInfoSection() {
return _buildSection(
title: '基本信息',
icon: Icons.work_outline,
children: [
_buildEditField(
label: '职业',
value: _memory?.occupation,
onChanged: (value) =>
_updateMemory(_memory!.copyWith(occupation: value)),
),
],
);
}
Widget _buildExpertiseSection() {
return _buildSection(
title: '专长',
icon: Icons.psychology_outlined,
count: _memory?.expertise.length ?? 0,
children: [
_buildTagsSection(
tags: _memory?.expertise ?? [],
onAdd: (tag) {
_updateMemory(
_memory!.copyWith(expertise: [..._memory!.expertise, tag]),
);
},
onRemove: (index) {
final newExpertise = List<String>.from(_memory!.expertise)
..removeAt(index);
_updateMemory(_memory!.copyWith(expertise: newExpertise));
},
),
],
);
}
Widget _buildPreferredToolsSection() {
return _buildSection(
title: '偏好工具',
icon: Icons.build_outlined,
count: _memory?.preferredTools.length ?? 0,
children: [
_buildTagsSection(
tags: _memory?.preferredTools ?? [],
onAdd: (tag) {
_updateMemory(
_memory!.copyWith(
preferredTools: [..._memory!.preferredTools, tag],
),
);
},
onRemove: (index) {
final newTools = List<String>.from(_memory!.preferredTools)
..removeAt(index);
_updateMemory(_memory!.copyWith(preferredTools: newTools));
},
),
],
);
}
Widget _buildProjectsSection() {
return _buildSection(
title: '当前项目',
icon: Icons.folder_outlined,
count: _memory?.currentProjects.length ?? 0,
children: [
if (_memory?.currentProjects.isEmpty ?? true)
_buildEmptySection('暂无项目')
else
..._memory!.currentProjects.asMap().entries.map((entry) {
final index = entry.key;
final project = entry.value;
return _buildProjectItem(project, index);
}),
const SizedBox(height: AppSpacing.sm),
_buildAddButton('添加项目', () {
final newProjects = List<CurrentProject>.from(
_memory!.currentProjects,
)..add(CurrentProject(name: '新项目'));
_updateMemory(_memory!.copyWith(currentProjects: newProjects));
}),
],
);
}
Widget _buildProjectItem(CurrentProject project, int index) {
return Container(
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: _buildEditField(
label: '项目名称',
value: project.name,
onChanged: (value) {
final newProjects = List<CurrentProject>.from(
_memory!.currentProjects,
);
newProjects[index] = project.copyWith(name: value);
_updateMemory(
_memory!.copyWith(currentProjects: newProjects),
);
},
),
),
AppPressable(
onTap: () {
final newProjects = List<CurrentProject>.from(
_memory!.currentProjects,
)..removeAt(index);
_updateMemory(
_memory!.copyWith(currentProjects: newProjects),
);
},
borderRadius: BorderRadius.circular(AppRadius.sm),
child: Container(
padding: const EdgeInsets.all(AppSpacing.xs),
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
),
),
],
),
const SizedBox(height: AppSpacing.sm),
Row(
children: [
Expanded(
child: _buildEditField(
label: '状态',
value: project.status,
onChanged: (value) {
final newProjects = List<CurrentProject>.from(
_memory!.currentProjects,
);
newProjects[index] = project.copyWith(status: value);
_updateMemory(
_memory!.copyWith(currentProjects: newProjects),
);
},
),
),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: _buildEditField(
label: '优先级',
value: project.priority,
onChanged: (value) {
final newProjects = List<CurrentProject>.from(
_memory!.currentProjects,
);
newProjects[index] = project.copyWith(priority: value);
_updateMemory(
_memory!.copyWith(currentProjects: newProjects),
);
},
),
),
],
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '描述',
value: project.description,
onChanged: (value) {
final newProjects = List<CurrentProject>.from(
_memory!.currentProjects,
);
newProjects[index] = project.copyWith(description: value);
_updateMemory(_memory!.copyWith(currentProjects: newProjects));
},
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '截止日期',
value: project.deadline?.toIso8601String().split('T').first,
onChanged: (value) {
final newProjects = List<CurrentProject>.from(
_memory!.currentProjects,
);
newProjects[index] = project.copyWith(
deadline: value.isNotEmpty ? DateTime.tryParse(value) : null,
);
_updateMemory(_memory!.copyWith(currentProjects: newProjects));
},
),
],
),
);
}
Widget _buildTeamMembersSection() {
return _buildSection(
title: '团队成员',
icon: Icons.groups_outlined,
count: _memory?.teamMembers.length ?? 0,
children: [
if (_memory?.teamMembers.isEmpty ?? true)
_buildEmptySection('暂无团队成员')
else
..._memory!.teamMembers.asMap().entries.map((entry) {
final index = entry.key;
final member = entry.value;
return _buildTeamMemberItem(member, index);
}),
const SizedBox(height: AppSpacing.sm),
_buildAddButton('添加成员', () {
final newMembers = List<TeamMember>.from(_memory!.teamMembers)
..add(TeamMember(name: '新成员'));
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
}),
],
);
}
Widget _buildTeamMemberItem(TeamMember member, int index) {
return Container(
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: _buildEditField(
label: '姓名',
value: member.name,
onChanged: (value) {
final newMembers = List<TeamMember>.from(
_memory!.teamMembers,
);
newMembers[index] = member.copyWith(name: value);
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
},
),
),
AppPressable(
onTap: () {
final newMembers = List<TeamMember>.from(_memory!.teamMembers)
..removeAt(index);
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
},
borderRadius: BorderRadius.circular(AppRadius.sm),
child: Container(
padding: const EdgeInsets.all(AppSpacing.xs),
child: Icon(Icons.close, size: 18, color: AppColors.slate400),
),
),
],
),
const SizedBox(height: AppSpacing.sm),
Row(
children: [
Expanded(
child: _buildEditField(
label: '角色',
value: member.role,
onChanged: (value) {
final newMembers = List<TeamMember>.from(
_memory!.teamMembers,
);
newMembers[index] = member.copyWith(role: value);
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
},
),
),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: _buildEditField(
label: '关系',
value: member.relationship,
onChanged: (value) {
final newMembers = List<TeamMember>.from(
_memory!.teamMembers,
);
newMembers[index] = member.copyWith(relationship: value);
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
},
),
),
],
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '联系方式',
value: member.preferredContactChannel,
onChanged: (value) {
final newMembers = List<TeamMember>.from(_memory!.teamMembers);
newMembers[index] = member.copyWith(
preferredContactChannel: value,
);
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
},
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '备注',
value: member.notes,
onChanged: (value) {
final newMembers = List<TeamMember>.from(_memory!.teamMembers);
newMembers[index] = member.copyWith(notes: value);
_updateMemory(_memory!.copyWith(teamMembers: newMembers));
},
),
],
),
);
}
Widget _buildWorkHabitsSection() {
final habits = _memory!.workHabits;
return _buildSection(
title: '工作习惯',
icon: Icons.schedule_outlined,
children: [
_buildEditField(
label: '通知渠道',
value: habits.notificationChannel,
onChanged: (value) {
_updateMemory(
_memory!.copyWith(
workHabits: habits.copyWith(notificationChannel: value),
),
);
},
),
const SizedBox(height: AppSpacing.sm),
_buildEditField(
label: '备注',
value: habits.notes,
onChanged: (value) {
_updateMemory(
_memory!.copyWith(workHabits: habits.copyWith(notes: value)),
);
},
),
],
);
}
Widget _buildTeamContextSection() {
return _buildSection(
title: '团队背景',
icon: Icons.business_outlined,
children: [
_buildEditField(
label: '团队背景描述',
value: _memory?.teamContext,
onChanged: (value) =>
_updateMemory(_memory!.copyWith(teamContext: value)),
),
],
);
}
Widget _buildWorkRulesSection() {
return _buildSection(
title: '工作规则',
icon: Icons.rule_outlined,
children: [
_buildTagsSection(
tags: _memory?.workRules ?? [],
onAdd: (tag) {
_updateMemory(
_memory!.copyWith(workRules: [..._memory!.workRules, tag]),
);
},
onRemove: (index) {
final newRules = List<String>.from(_memory!.workRules)
..removeAt(index);
_updateMemory(_memory!.copyWith(workRules: newRules));
},
),
],
);
}
Widget _buildSection({
required String title,
required IconData icon,
int? count,
required List<Widget> children,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, size: 18, color: AppColors.violet500),
const SizedBox(width: AppSpacing.sm),
Text(
title,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: AppColors.slate800,
),
),
if (count != null) ...[
const SizedBox(width: AppSpacing.xs),
Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.sm,
vertical: 2,
),
decoration: BoxDecoration(
color: AppColors.violet500.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(AppRadius.full),
),
child: Text(
'$count',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: AppColors.violet600,
),
),
),
],
],
),
const SizedBox(height: AppSpacing.md),
...children,
],
);
}
Widget _buildEditField({
required String label,
String? value,
required ValueChanged<String> onChanged,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: AppColors.slate500,
),
),
const SizedBox(height: AppSpacing.xs),
Container(
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: TextFormField(
initialValue: value,
onChanged: onChanged,
style: const TextStyle(fontSize: 14, color: AppColors.slate800),
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
border: InputBorder.none,
hintText: '输入$label',
hintStyle: TextStyle(color: AppColors.slate400, fontSize: 14),
),
),
),
],
);
}
Widget _buildEmptySection(String message) {
return Container(
padding: const EdgeInsets.all(AppSpacing.lg),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(color: AppColors.borderSecondary),
),
child: Center(
child: Text(
message,
style: TextStyle(fontSize: 14, color: AppColors.slate400),
),
),
);
}
Widget _buildTagsSection({
required List<String> tags,
required ValueChanged<String> onAdd,
required ValueChanged<int> onRemove,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: AppSpacing.sm,
runSpacing: AppSpacing.sm,
children: [
...tags.asMap().entries.map((entry) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColors.violet500.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(AppRadius.full),
border: Border.all(
color: AppColors.violet500.withValues(alpha: 0.3),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
entry.value,
style: TextStyle(
fontSize: 13,
color: AppColors.violet600,
),
),
const SizedBox(width: AppSpacing.xs),
AppPressable(
onTap: () => onRemove(entry.key),
borderRadius: BorderRadius.circular(AppRadius.full),
child: Icon(
Icons.close,
size: 14,
color: AppColors.violet500,
),
),
],
),
);
}),
AppPressable(
onTap: () => _showAddTagDialog(onAdd),
borderRadius: BorderRadius.circular(AppRadius.full),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.full),
border: Border.all(
color: AppColors.borderSecondary,
style: BorderStyle.solid,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.add, size: 14, color: AppColors.slate500),
const SizedBox(width: AppSpacing.xs),
Text(
'添加',
style: TextStyle(fontSize: 13, color: AppColors.slate500),
),
],
),
),
),
],
),
],
);
}
void _showAddTagDialog(ValueChanged<String> onAdd) {
final controller = TextEditingController();
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('添加'),
content: TextField(
controller: controller,
autofocus: true,
decoration: const InputDecoration(hintText: '输入内容'),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
TextButton(
onPressed: () {
if (controller.text.isNotEmpty) {
onAdd(controller.text);
}
Navigator.pop(context);
},
child: const Text('添加'),
),
],
),
);
}
Widget _buildAddButton(String text, VoidCallback onTap) {
return AppPressable(
onTap: onTap,
borderRadius: BorderRadius.circular(AppRadius.md),
child: Container(
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColors.surfaceSecondary,
borderRadius: BorderRadius.circular(AppRadius.md),
border: Border.all(
color: AppColors.borderSecondary,
style: BorderStyle.solid,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add, size: 18, color: AppColors.violet500),
const SizedBox(width: AppSpacing.xs),
Text(
text,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.violet600,
),
),
],
),
),
);
}
}