- photo_upload_provider/photo_guide_page:4 类照片(大头照/正面/侧面/背面)拍照或相册上传 - body_provider/body_tune_page:身高 145-200cm / 体重 / 肤色 1-5 滑杆设置 - avatar_provider:化身构建(同步 + 异步轮询兜底) - profile_page:形象主页聚合化身/照片/身形状态 + 登出 - wardrobe_provider/wardrobe_page/wardrobe_upload_page:网格展示 + 分类筛选 + 长按删除 + 表单上传 - AppConfig.resolveUrl 相对路径拼接;新增 /photo-guide /body-tune /wardrobe-upload 路由
146 lines
5.5 KiB
Dart
146 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../core/config/app_config.dart';
|
|
import '../../shared/widgets/empty_view.dart';
|
|
import '../../shared/widgets/error_view.dart';
|
|
import '../../shared/widgets/loading_view.dart';
|
|
import 'wardrobe_provider.dart';
|
|
|
|
/// 衣橱:服装网格 + 长按删除 + 上传入口
|
|
class WardrobePage extends ConsumerStatefulWidget {
|
|
const WardrobePage({super.key});
|
|
|
|
@override
|
|
ConsumerState<WardrobePage> createState() => _WardrobePageState();
|
|
}
|
|
|
|
class _WardrobePageState extends ConsumerState<WardrobePage> {
|
|
String? _filter; // 当前分类筛选,null = 全部
|
|
|
|
Future<void> _confirmDelete(WardrobeItemInfo item) async {
|
|
final ok = await showDialog<bool>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('删除这件服装?'),
|
|
content: Text('「${item.category}」删除后不可恢复'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx, false),
|
|
child: const Text('取消')),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(ctx, true),
|
|
child: const Text('删除')),
|
|
],
|
|
),
|
|
);
|
|
if (ok == true) {
|
|
await ref.read(wardrobeProvider.notifier).delete(item.id);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final items = ref.watch(wardrobeProvider);
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('我的衣橱')),
|
|
body: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 48,
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
children: [
|
|
for (final c in [null, ...wardrobeCategories])
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 8),
|
|
child: ChoiceChip(
|
|
label: Text(c ?? '全部'),
|
|
selected: _filter == c,
|
|
onSelected: (_) => setState(() => _filter = c),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: items.when(
|
|
loading: () => const LoadingView(text: '加载衣橱...'),
|
|
error: (e, _) => ErrorView(
|
|
message: e.toString().replaceFirst('Exception: ', ''),
|
|
onRetry: () => ref.read(wardrobeProvider.notifier).refresh(),
|
|
),
|
|
data: (list) {
|
|
final shown = _filter == null
|
|
? list
|
|
: list.where((i) => i.category == _filter).toList();
|
|
if (shown.isEmpty) {
|
|
return EmptyView(
|
|
message: '衣橱还是空的,上传你的服装吧',
|
|
actionText: '上传服装',
|
|
onAction: () => context.go('/wardrobe-upload'));
|
|
}
|
|
return GridView.builder(
|
|
padding: const EdgeInsets.all(12),
|
|
gridDelegate:
|
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
mainAxisSpacing: 12,
|
|
crossAxisSpacing: 12,
|
|
childAspectRatio: 0.8,
|
|
),
|
|
itemCount: shown.length,
|
|
itemBuilder: (ctx, i) {
|
|
final item = shown[i];
|
|
return GestureDetector(
|
|
onLongPress: () => _confirmDelete(item),
|
|
child: Card(
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Expanded(
|
|
child: item.photoUrl.isEmpty
|
|
? const Icon(Icons.checkroom,
|
|
size: 48, color: Colors.grey)
|
|
: Image.network(
|
|
AppConfig.resolveUrl(item.photoUrl),
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, _, _) => const Icon(
|
|
Icons.broken_image_outlined,
|
|
size: 48,
|
|
color: Colors.grey),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Text(
|
|
'${item.category}${item.season.isNotEmpty ? ' · ${item.season}' : ''}',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
fontSize: 13, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
onPressed: () => context.go('/wardrobe-upload'),
|
|
icon: const Icon(Icons.add),
|
|
label: const Text('上传'),
|
|
),
|
|
);
|
|
}
|
|
}
|