// 搜索页面 — 日记搜索 + 标签筛选 import 'package:flutter/material.dart'; import 'package:nuanji_app/core/theme/app_colors.dart'; import 'package:nuanji_app/data/models/journal_entry.dart'; /// 搜索页面 — 全文搜索日记(Phase 1 占位 UI) class SearchPage extends StatefulWidget { const SearchPage({super.key}); @override State createState() => _SearchPageState(); } class _SearchPageState extends State { final _searchController = TextEditingController(); bool _hasSearched = false; // Phase 1 占位数据 final _recentTags = ['日常', '学校', '旅行', '美食', '读书', '心情']; final _moodFilters = Mood.values; @override void dispose() { _searchController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final theme = Theme.of(context); final colorScheme = theme.colorScheme; return Scaffold( appBar: AppBar( title: TextField( controller: _searchController, decoration: InputDecoration( hintText: '搜索日记...', hintStyle: theme.textTheme.bodyLarge?.copyWith( color: colorScheme.onSurface.withValues(alpha: 0.4), ), border: InputBorder.none, prefixIcon: const Icon(Icons.search), suffixIcon: _searchController.text.isNotEmpty ? IconButton( icon: const Icon(Icons.clear), onPressed: () { _searchController.clear(); setState(() => _hasSearched = false); }, ) : null, ), textInputAction: TextInputAction.search, onSubmitted: (_) => _doSearch(), ), ), body: _hasSearched ? _buildSearchResults(context, colorScheme) : _buildSuggestions(context, theme, colorScheme), ); } void _doSearch() { setState(() => _hasSearched = true); } Widget _buildSuggestions(BuildContext context, ThemeData theme, ColorScheme colorScheme) { return SingleChildScrollView( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('常用标签', style: theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600)), const SizedBox(height: 8), Wrap( spacing: 8, runSpacing: 8, children: _recentTags.map((tag) { return ActionChip( label: Text(tag), onPressed: () { _searchController.text = tag; _doSearch(); }, ); }).toList(), ), const SizedBox(height: 24), Text('按心情筛选', style: theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600)), const SizedBox(height: 12), Wrap( spacing: 12, runSpacing: 12, children: _moodFilters.map((mood) { final color = AppColors.moodColors[mood.value] ?? colorScheme.primary; return GestureDetector( onTap: () { _searchController.text = _moodLabel(mood); _doSearch(); }, child: Column( children: [ Container( width: 48, height: 48, decoration: BoxDecoration( shape: BoxShape.circle, color: color.withValues(alpha: 0.15), ), alignment: Alignment.center, child: Text(_moodEmoji(mood), style: const TextStyle(fontSize: 24)), ), const SizedBox(height: 4), Text(_moodLabel(mood), style: theme.textTheme.labelSmall), ], ), ); }).toList(), ), ], ), ); } Widget _buildSearchResults(BuildContext context, ColorScheme colorScheme) { return Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.search_off_rounded, size: 48, color: colorScheme.onSurface.withValues(alpha: 0.2)), const SizedBox(height: 12), Text( 'Phase 1: 搜索功能待 Isar FTS 集成', style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: colorScheme.onSurface.withValues(alpha: 0.5), ), ), ], ), ); } String _moodEmoji(Mood mood) => switch (mood) { Mood.happy => '😊', Mood.calm => '😌', Mood.sad => '😢', Mood.angry => '😠', Mood.thinking => '🤔', }; String _moodLabel(Mood mood) => switch (mood) { Mood.happy => '开心', Mood.calm => '平静', Mood.sad => '难过', Mood.angry => '生气', Mood.thinking => '思考', }; }