import 'dart:io'; import 'package:bootstrap_icons/bootstrap_icons.dart'; import 'package:flutter/material.dart'; import 'package:english_learning/core/utils/styles/theme.dart'; class UserAvatar extends StatelessWidget { final String? pictureUrl; final double radius; final String baseUrl; final Function()? onImageSelected; final File? selectedImage; const UserAvatar({ super.key, this.pictureUrl, this.radius = 55, required this.baseUrl, this.onImageSelected, this.selectedImage, }); @override Widget build(BuildContext context) { return GestureDetector( onTap: onImageSelected, child: CircleAvatar( radius: radius, backgroundColor: AppColors.primaryColor, child: _getAvatarContent(), ), ); } Widget _getAvatarContent() { if (selectedImage != null) { return ClipOval( child: Image.file( selectedImage!, fit: BoxFit.cover, width: radius * 2, height: radius * 2, ), ); } else if (pictureUrl != null && pictureUrl!.isNotEmpty) { return ClipOval( child: Image.network( '$baseUrl$pictureUrl', fit: BoxFit.cover, width: radius * 2, height: radius * 2, errorBuilder: (context, error, stackTrace) { print('Error loading avatar image: $error'); return _buildDefaultIcon(); }, ), ); } else { return _buildDefaultIcon(); } } Widget _buildDefaultIcon() { return Icon( BootstrapIcons.person, color: AppColors.whiteColor, size: radius * 1.2, ); } }