85 lines
2.4 KiB
Dart
85 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:arcx/app/app_theme.dart';
|
|
import 'package:arcx/data/local/models/models.dart';
|
|
import 'package:arcx/features/profile/application/profile_controller.dart';
|
|
import 'package:arcx/features/profile/presentation/avatar_image.dart';
|
|
|
|
class ProfileCard extends ConsumerWidget {
|
|
const ProfileCard({super.key, required this.onEdit});
|
|
|
|
final VoidCallback onEdit;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final profileAsync = ref.watch(profileProvider);
|
|
return profileAsync.when(
|
|
loading: () => const _CardShell(child: SizedBox(height: 64)),
|
|
error: (e, _) => _CardShell(child: Text('加载失败:$e')),
|
|
data: (profile) => _CardShell(
|
|
child: Row(
|
|
children: [
|
|
_Avatar(profile: profile),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
profile.nickname,
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'本地用户',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: AppTheme.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.edit_outlined),
|
|
color: AppTheme.primary,
|
|
onPressed: onEdit,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Avatar extends StatelessWidget {
|
|
const _Avatar({required this.profile});
|
|
|
|
final UserProfile profile;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CircleAvatar(
|
|
radius: 30,
|
|
backgroundColor: AppTheme.surfaceMuted,
|
|
backgroundImage: resolveAvatarImage(profile),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _CardShell extends StatelessWidget {
|
|
const _CardShell({required this.child});
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
child: Padding(padding: const EdgeInsets.all(16), child: child),
|
|
);
|
|
}
|
|
}
|