74 lines
2.7 KiB
Dart
74 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../shared/app_toast.dart';
|
|
import '../../shared/widgets/avatar_viewer.dart';
|
|
import '../../shared/widgets/loading_view.dart';
|
|
import 'avatar_provider.dart';
|
|
|
|
/// 3D 化身查看页
|
|
class AvatarViewerPage extends ConsumerWidget {
|
|
const AvatarViewerPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final avatar = ref.watch(avatarProvider);
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('我的 3D 化身')),
|
|
body: avatar.when(
|
|
loading: () => const LoadingView(text: '加载化身...'),
|
|
error: (e, _) => Center(child: Text('加载失败:$e')),
|
|
data: (a) => ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
AvatarViewer(
|
|
glbUrl: a.glbUrl,
|
|
framesUrl: a.framesUrl,
|
|
title: '我的 3D 化身',
|
|
subtitle: a.built
|
|
? '脸型模板 ${a.faceTemplateId} · 体型模板 ${a.bodyTemplateId} · 肤色 ${a.skinToneIndex}'
|
|
: '尚未构建化身',
|
|
),
|
|
const SizedBox(height: 12),
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text('构建说明',
|
|
style: TextStyle(
|
|
fontSize: 15, fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'化身基于你的三视角全身照(正面/侧面/背面)由 AI 生成 3D 形象,'
|
|
'构建过程通常需要 1-3 分钟。',
|
|
style: TextStyle(fontSize: 13, color: Colors.grey),
|
|
),
|
|
const SizedBox(height: 12),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton.icon(
|
|
onPressed: () async {
|
|
await ref
|
|
.read(avatarProvider.notifier)
|
|
.buildAvatar();
|
|
if (context.mounted) {
|
|
showToast('化身构建完成');
|
|
}
|
|
},
|
|
icon: const Icon(Icons.refresh),
|
|
label: const Text('重新构建化身'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|