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

212 lines
6.0 KiB
Dart
Raw Normal View History

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 '../widgets/settings_page_scaffold.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 SettingsPageScaffold(
title: '我的记忆',
onBack: () => context.pop(),
body: 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(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
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: 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 _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: AppColors.borderSecondary),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
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: 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);
}
}