snap_wish/lib/pages/add_photo_page.dart
2025-08-28 14:44:36 +08:00

170 lines
5.2 KiB
Dart

import 'package:flutter/material.dart';
class AddPhotoPage extends StatefulWidget {
const AddPhotoPage({super.key});
@override
State<AddPhotoPage> createState() => _AddPhotoPageState();
}
class _AddPhotoPageState extends State<AddPhotoPage> {
String? _selectedCategory;
final TextEditingController _tagsController = TextEditingController();
final List<String> _tags = [];
// TODO: 替换为真实文件夹数据
final List<String> _categories = ['默认分类', '人像', '风景', '建筑'];
@override
void dispose() {
_tagsController.dispose();
super.dispose();
}
void _selectPhoto() {
// TODO: 实现选择本地照片功能
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('选择照片功能待实现')),
);
}
void _addTag(String text) {
final tag = text.trim();
if (tag.isNotEmpty && !_tags.contains(tag)) {
setState(() {
_tags.add(tag);
});
_tagsController.clear();
}
}
void _removeTag(String tag) {
setState(() {
_tags.remove(tag);
});
}
void _savePhoto() {
if (_selectedCategory == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('请选择文件夹')),
);
return;
}
// TODO: 实现保存照片功能
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('照片已保存到 $_selectedCategory')),
);
Navigator.pop(context);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('添加照片'),
actions: [
TextButton(
onPressed: _savePhoto,
child: const Text('保存', style: TextStyle(color: Colors.white)),
),
],
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 照片预览区域
GestureDetector(
onTap: _selectPhoto,
child: Container(
height: 200,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.grey[400]!),
),
child: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add_photo_alternate, size: 48, color: Colors.grey),
SizedBox(height: 8),
Text('点击选择照片', style: TextStyle(color: Colors.grey)),
],
),
),
),
),
const SizedBox(height: 24),
// 文件夹选择
const Text('选择文件夹', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 8),
DropdownButtonFormField<String>(
value: _selectedCategory,
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: '请选择文件夹',
),
items: _categories.map((category) {
return DropdownMenuItem(
value: category,
child: Text(category),
);
}).toList(),
onChanged: (value) {
setState(() {
_selectedCategory = value;
});
},
),
const SizedBox(height: 24),
// 标签输入
const Text('添加标签', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 8),
TextField(
controller: _tagsController,
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: '输入标签(支持 #标签 格式)',
suffixIcon: IconButton(
icon: const Icon(Icons.add),
onPressed: () => _addTag(_tagsController.text),
),
),
onSubmitted: _addTag,
onChanged: (value) {
// 处理 # 开头的标签输入
if (value.endsWith(' ') || value.endsWith('#')) {
final parts = value.split('#');
if (parts.length > 1) {
final tag = parts.last.trim();
if (tag.isNotEmpty) {
_addTag(tag);
}
}
}
},
),
const SizedBox(height: 12),
// 标签列表
Wrap(
spacing: 8,
runSpacing: 4,
children: _tags.map((tag) => Chip(
label: Text('#$tag'),
onDeleted: () => _removeTag(tag),
deleteIcon: const Icon(Icons.close, size: 16),
)).toList(),
),
],
),
),
);
}
}