- 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 路由
77 lines
2.1 KiB
Dart
77 lines
2.1 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../core/auth/auth_provider.dart';
|
|
|
|
/// 服装分类(与后端校验一致)
|
|
const wardrobeCategories = ['上衣', '下装', '鞋', '配饰'];
|
|
|
|
const wardrobeSeasons = ['春', '夏', '秋', '冬', '四季'];
|
|
|
|
class WardrobeItemInfo {
|
|
final int id;
|
|
final String photoUrl;
|
|
final String category;
|
|
final String season;
|
|
final String styleTags;
|
|
final String colorInfo;
|
|
|
|
const WardrobeItemInfo({
|
|
required this.id,
|
|
required this.photoUrl,
|
|
required this.category,
|
|
required this.season,
|
|
required this.styleTags,
|
|
required this.colorInfo,
|
|
});
|
|
}
|
|
|
|
class WardrobeNotifier extends AsyncNotifier<List<WardrobeItemInfo>> {
|
|
@override
|
|
Future<List<WardrobeItemInfo>> build() async {
|
|
final api = ref.read(apiClientProvider);
|
|
final list = await api.get<List<dynamic>>('/wardrobe/list');
|
|
return list
|
|
.map((e) => WardrobeItemInfo(
|
|
id: (e['id'] as num).toInt(),
|
|
photoUrl: e['photo_url'] as String? ?? '',
|
|
category: e['category'] as String? ?? '',
|
|
season: e['season'] as String? ?? '',
|
|
styleTags: e['style_tags'] as String? ?? '',
|
|
colorInfo: e['color_info'] as String? ?? '',
|
|
))
|
|
.toList();
|
|
}
|
|
|
|
Future<void> upload(
|
|
String filePath, {
|
|
required String category,
|
|
String season = '',
|
|
String styleTags = '',
|
|
String colorInfo = '',
|
|
}) async {
|
|
final api = ref.read(apiClientProvider);
|
|
await api.upload('/wardrobe/upload', {
|
|
'category': category,
|
|
'season': season,
|
|
'style_tags': styleTags,
|
|
'color_info': colorInfo,
|
|
}, 'file', filePath);
|
|
await refresh();
|
|
}
|
|
|
|
Future<void> delete(int id) async {
|
|
final api = ref.read(apiClientProvider);
|
|
await api.post('/wardrobe/delete', {'id': id});
|
|
await refresh();
|
|
}
|
|
|
|
Future<void> refresh() async {
|
|
state = const AsyncLoading();
|
|
state = await AsyncValue.guard(build);
|
|
}
|
|
}
|
|
|
|
final wardrobeProvider =
|
|
AsyncNotifierProvider<WardrobeNotifier, List<WardrobeItemInfo>>(
|
|
WardrobeNotifier.new);
|