Files
social-app/apps/lib/features/settings/ui/screens/memory_screen.dart
T

240 lines
6.9 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../core/theme/design_tokens.dart';
import '../../../../shared/widgets/page_header.dart' as widgets;
import '../../data/services/memory_service.dart';
class MemoryScreen extends StatefulWidget {
const MemoryScreen({super.key});
@override
State<MemoryScreen> createState() => _MemoryScreenState();
}
class _MemoryScreenState extends State<MemoryScreen> {
bool _memoryEnabled = true;
final MemoryService _memoryService = MemoryService();
late List<MemoryItemModel> _memoryItems;
@override
void initState() {
super.initState();
_memoryItems = _memoryService.getMemoryItems();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.surfaceSecondary,
body: SafeArea(
child: Column(
children: [
widgets.PageHeader(leading: widgets.BackButton(), height: 56),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(20, 12, 20, 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildToggleCard(),
if (_memoryItems.isNotEmpty) ...[
const SizedBox(height: 14),
_buildListTitle(),
const SizedBox(height: 8),
_buildMemoryList(),
],
const SizedBox(height: 20),
_buildManageButton(),
],
),
),
),
],
),
),
);
}
Widget _buildToggleCard() {
return Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'启用记忆',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.slate900,
),
),
_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),
),
),
),
],
),
);
}
Widget _buildListTitle() {
return const Text(
'记忆条目',
style: 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: const Color(0xFFE1E8F3)),
),
child: Column(
children: [
for (int i = 0; i < _memoryItems.length; i++) ...[
_buildMemoryItem(_memoryItems[i]),
if (i < _memoryItems.length - 1) const SizedBox(height: 10),
],
],
),
);
}
Widget _buildMemoryItem(MemoryItemModel item) {
return GestureDetector(
onTap: () {},
child: Container(
height: 74,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: AppColors.surfaceTertiary,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xFFE8EDF7)),
),
child: Row(
children: [
Container(
width: 32,
height: 32,
decoration: BoxDecoration(
color: AppColors.surfaceInfo,
borderRadius: BorderRadius.circular(10),
),
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: Color(0xFF9AAAC1)),
],
),
),
);
}
Widget _buildManageButton() {
return GestureDetector(
onTap: () {},
child: Container(
height: 44,
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xFFDCE6F4)),
),
child: const Center(
child: Text(
'管理记忆条目',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.slate700,
),
),
),
),
);
}
Widget _buildToggle(bool value, ValueChanged<bool> onChanged) {
return GestureDetector(
onTap: () => onChanged(!value),
child: Container(
width: 44,
height: 24,
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
color: value ? const Color(0xFFBFDBFE) : const Color(0xFFF1F5FC),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: value ? const Color(0xFF93C5FD) : const Color(0xFFD5DFEE),
),
),
child: AnimatedAlign(
duration: const Duration(milliseconds: 150),
alignment: value ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFFCCDDF8)),
),
),
),
),
);
}
}