114 lines
3.6 KiB
Dart
114 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_common/utils/date_utils.dart';
|
|
import 'package:flutter_common/widget/common_widget.dart';
|
|
import 'package:food_hub_app/config/app_config.dart';
|
|
import 'package:food_hub_app/models/session.dart';
|
|
import 'package:food_hub_app/widgets/common/index.dart';
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
|
|
class ProfileInfo extends StatelessWidget {
|
|
final User user;
|
|
|
|
const ProfileInfo({super.key, required this.user});
|
|
|
|
Widget _buildAvatar(BuildContext context, User user) {
|
|
if (user.avatar == null) {
|
|
return TDAvatar(
|
|
size: TDAvatarSize.large,
|
|
type: TDAvatarType.customText,
|
|
shape: TDAvatarShape.circle,
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
text: user.username.isNotEmpty ? user.username[0] : '?',
|
|
);
|
|
} else {
|
|
return TDAvatar(
|
|
size: TDAvatarSize.large,
|
|
type: TDAvatarType.normal,
|
|
fit: BoxFit.contain,
|
|
avatarUrl: '${AppConfig.imageBaseUrl}/${user.avatar}',
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _buildInfoItem({
|
|
required BuildContext context,
|
|
required IconData icon,
|
|
required String text,
|
|
}) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: 16, color: colors.primary),
|
|
const SizedBox(width: 6),
|
|
Text(text),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CommonCard(
|
|
child: Column(
|
|
children: [
|
|
_buildAvatar(context, user),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
user.username,
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 8),
|
|
if (user.tags != null && user.tags!.isNotEmpty)
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children:
|
|
user.tags!.map((tag) => buildTag(context, tag)).toList(),
|
|
),
|
|
if (user.tags != null && user.tags!.isNotEmpty)
|
|
const SizedBox(height: 8),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: [
|
|
if (user.area != null && user.area!.length >= 2)
|
|
_buildInfoItem(
|
|
context: context,
|
|
icon: Icons.location_on,
|
|
text: '${user.area![0]}-${user.area![1]}',
|
|
),
|
|
if (user.birthDate != null)
|
|
_buildInfoItem(
|
|
context: context,
|
|
icon: Icons.cake,
|
|
text: formatDate(user.birthDate!),
|
|
),
|
|
if (user.job != null && user.job!.isNotEmpty)
|
|
_buildInfoItem(
|
|
context: context,
|
|
icon: Icons.work,
|
|
text: user.job!,
|
|
),
|
|
if (user.phoneNumber != null && user.phoneNumber!.isNotEmpty)
|
|
_buildInfoItem(
|
|
context: context,
|
|
icon: Icons.phone_android,
|
|
text: user.phoneNumber!,
|
|
),
|
|
if (user.email != null && user.email!.isNotEmpty)
|
|
_buildInfoItem(
|
|
context: context,
|
|
icon: Icons.email,
|
|
text: user.email!,
|
|
),
|
|
],
|
|
),
|
|
if (user.description != null && user.description!.isNotEmpty)
|
|
const SizedBox(height: 8),
|
|
if (user.description != null && user.description!.isNotEmpty)
|
|
Text(user.description!),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|