89 lines
2.3 KiB
Dart
89 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../core/theme/app_typography.dart';
|
|
import '../../../services/social/rider_profile_models.dart';
|
|
|
|
/// Renders a rider's avatar using their preset styling or custom photo URL.
|
|
class AvatarBadge extends StatelessWidget {
|
|
final String? avatarPreset;
|
|
final String? photoUrl;
|
|
final String displayName;
|
|
final double radius;
|
|
final VoidCallback? onTap;
|
|
final bool isSelected;
|
|
|
|
const AvatarBadge({
|
|
super.key,
|
|
this.avatarPreset,
|
|
this.photoUrl,
|
|
required this.displayName,
|
|
this.radius = 24.0,
|
|
this.onTap,
|
|
this.isSelected = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final preset = PresetAvatar.byId(avatarPreset);
|
|
final primaryColor = Color(preset.primaryColorHex);
|
|
final secondaryColor = Color(preset.secondaryColorHex);
|
|
|
|
Widget inner;
|
|
if (photoUrl != null && photoUrl!.trim().isNotEmpty) {
|
|
inner = CircleAvatar(
|
|
radius: radius,
|
|
backgroundColor: secondaryColor,
|
|
backgroundImage: NetworkImage(photoUrl!),
|
|
);
|
|
} else {
|
|
final initial = displayName.trim().isNotEmpty
|
|
? displayName.trim()[0].toUpperCase()
|
|
: 'R';
|
|
|
|
inner = CircleAvatar(
|
|
radius: radius,
|
|
backgroundColor: secondaryColor,
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(
|
|
color: primaryColor.withValues(alpha: 0.8),
|
|
width: 1.5,
|
|
),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
initial,
|
|
style: TextStyle(
|
|
color: primaryColor,
|
|
fontWeight: FontWeight.w900,
|
|
fontSize: radius * 0.9,
|
|
fontFamily: AppTypography.fontHeadline,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (isSelected) {
|
|
inner = Container(
|
|
padding: const EdgeInsets.all(3),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: Theme.of(context).colorScheme.primary, width: 2),
|
|
),
|
|
child: inner,
|
|
);
|
|
}
|
|
|
|
if (onTap != null) {
|
|
return InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(radius * 2),
|
|
child: inner,
|
|
);
|
|
}
|
|
|
|
return inner;
|
|
}
|
|
}
|