Insparkspokalen-ui/lib/teams/teamImage.dart
2025-05-30 09:47:41 +02:00

59 lines
1.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class TeamImage extends StatelessWidget {
final String? imageUrl;
final double size;
const TeamImage({Key? key, required this.imageUrl, this.size = 30})
: super(key: key);
@override
Widget build(BuildContext context) {
if (imageUrl == null || imageUrl!.isEmpty) {
return CircleAvatar(
radius: size / 2,
backgroundColor: Colors.white,
child: Icon(Icons.broken_image, size: size * 0.6, color: Colors.grey),
);
}
final lowerUrl = imageUrl!.toLowerCase();
Widget imageWidget;
if (lowerUrl.contains('svg')) {
imageWidget = SvgPicture.network(
imageUrl!,
width: size,
height: size,
placeholderBuilder:
(context) => const CircularProgressIndicator(strokeWidth: 1),
fit: BoxFit.cover,
);
} else {
imageWidget = Image.network(
imageUrl!,
width: size,
height: size,
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return const CircularProgressIndicator(strokeWidth: 1);
},
errorBuilder:
(context, error, stackTrace) =>
const Icon(Icons.broken_image, size: 24, color: Colors.grey),
);
}
return CircleAvatar(
radius: size / 2,
backgroundColor: Colors.white,
child: ClipOval(
child: SizedBox(width: size, height: size, child: imageWidget),
),
);
}
}