my_profile_avatar 1.0.0 copy "my_profile_avatar: ^1.0.0" to clipboard
my_profile_avatar: ^1.0.0 copied to clipboard

A customizable Flutter package for displaying profile avatars with support for network images, local files, name initials, and placeholder icons.

My Profile Avatar #

pub package License: MIT Flutter

A customizable Flutter package for displaying profile avatars with support for multiple image sources including network images, local files, name initials, and placeholder icons.

✨ Features #

  • 🌐 Network Images: Display avatars from URLs with built-in caching support
  • πŸ“ Local Files: Load avatar images from device storage
  • πŸ”€ Name Initials: Generate text-based avatars from user names
  • 🎭 Placeholder Icons: Show default avatar icons when no image is available
  • 🎨 Customizable Styling: Control size, colors, and border radius
  • ⏳ Loading States: Built-in loading indicators for network images
  • πŸ›‘οΈ Error Handling: Graceful fallbacks when images fail to load
  • πŸ“± Platform Support: Works on iOS, Android, Web, and Desktop

πŸ“± Screenshots #

Demo App Overview Interactive Controls
Demo Controls

πŸš€ Getting Started #

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  my_profile_avatar: ^1.0.0

Then run:

flutter pub get

Import #

import 'package:my_profile_avatar/my_profile_avatar.dart';

πŸ“– Usage #

Basic Usage #

MyProfileAvatar(
  style: MyProfileAvatarStyle(
    size: 60,
    color: Colors.blue,
    radius: 30,
  ),
  urlImage: 'https://example.com/avatar.jpg',
)

Different Avatar Types #

Network Image Avatar

MyProfileAvatar(
  style: MyProfileAvatarStyle(
    size: 80,
    color: Colors.blue,
    radius: 40,
  ),
  urlImage: 'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg',
)

Name Initials Avatar

MyProfileAvatar(
  style: MyProfileAvatarStyle(
    size: 60,
    color: Colors.green,
    radius: 30,
  ),
  name: 'John Doe',
)

Local File Avatar

MyProfileAvatar(
  style: MyProfileAvatarStyle(
    size: 100,
    color: Colors.purple,
    radius: 50,
  ),
  pathImage: '/path/to/local/image.jpg',
)

Placeholder Avatar

MyProfileAvatar(
  style: MyProfileAvatarStyle(
    size: 50,
    color: Colors.grey,
    radius: 25,
  ),
  // No image sources provided - shows placeholder
)

Using the Type Factory Constructor #

For more explicit control over avatar types:

// Network image avatar
MyProfileAvatar.type(
  type: MyProfileAvatarType.network,
  value: 'https://example.com/avatar.jpg',
  style: MyProfileAvatarStyle(
    size: 60,
    color: Colors.blue,
  ),
)

// Name initials avatar
MyProfileAvatar.type(
  type: MyProfileAvatarType.name,
  value: 'Alice Johnson',
  style: MyProfileAvatarStyle(
    size: 80,
    color: Colors.green,
  ),
)

Styling Options #

The MyProfileAvatarStyle class provides extensive customization options:

MyProfileAvatarStyle(
  size: 100,        // Width and height in logical pixels
  color: Colors.blue, // Primary color for text, icons, and loading indicators
  radius: 50,       // Border radius (50 = perfect circle for size 100)
)

Common Styling Patterns

// Perfect circle
MyProfileAvatarStyle(
  size: 80,
  color: Colors.blue,
  radius: 40, // Half of size
)

// Rounded square
MyProfileAvatarStyle(
  size: 60,
  color: Colors.green,
  radius: 12,
)

// Sharp square
MyProfileAvatarStyle(
  size: 50,
  color: Colors.red,
  radius: 0,
)

πŸ”„ Priority System #

The widget automatically determines which content to display based on this priority order:

  1. Local File (pathImage) - Highest priority
  2. Network Image (urlImage)
  3. Name Initials (name)
  4. Placeholder Icon - Lowest priority (fallback)
MyProfileAvatar(
  style: MyProfileAvatarStyle(color: Colors.blue),
  pathImage: '/local/image.jpg',    // This will be shown
  urlImage: 'https://example.com/avatar.jpg', // Ignored
  name: 'John Doe',                 // Ignored
)

πŸ› οΈ Advanced Usage #

Custom Error Handling #

The widget includes built-in error handling, but you can also check the avatar type programmatically:

final avatar = MyProfileAvatar(
  style: MyProfileAvatarStyle(color: Colors.blue),
  urlImage: 'https://example.com/avatar.jpg',
);

// Check what type will be displayed
final avatarType = avatar.getType(); // MyProfileAvatarType.network
final avatarValue = avatar.getValue(); // 'https://example.com/avatar.jpg'

Integration with User Profiles #

class UserProfile extends StatelessWidget {
  final User user;

  const UserProfile({required this.user, super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        MyProfileAvatar(
          style: MyProfileAvatarStyle(
            size: 120,
            color: Theme.of(context).primaryColor,
            radius: 60,
          ),
          urlImage: user.profileImageUrl,
          name: user.fullName,
        ),
        const SizedBox(height: 16),
        Text(user.fullName, style: Theme.of(context).textTheme.headlineSmall),
      ],
    );
  }
}

πŸ“‹ API Reference #

MyProfileAvatar #

Parameter Type Description
style MyProfileAvatarStyle Required. Styling configuration for the avatar
name String? Optional name to display as initials
urlImage String? Optional URL for network image
pathImage String? Optional path to local image file

MyProfileAvatarStyle #

Parameter Type Default Description
color Color Required Primary color for text, icons, and indicators
size double 50.0 Width and height in logical pixels
radius double 100.0 Border radius for rounded corners

MyProfileAvatarType #

Value Description
placeholder Default placeholder icon
network Network image from URL
file Local file image
name Name initials as text

🀝 Contributing #

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup #

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/mohamedmaher-dev/my_profile_avatar.git
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes and add tests
  5. Run tests: flutter test
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to the branch: git push origin feature/amazing-feature
  8. Open a Pull Request

πŸ› Issues #

If you encounter any issues or have feature requests, please file them in the issues section.

πŸ“„ License #

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments #


Made with ❀️ for the Flutter community

1
likes
160
points
120
downloads
screenshot

Publisher

verified publishermomaher.dev

Weekly Downloads

A customizable Flutter package for displaying profile avatars with support for network images, local files, name initials, and placeholder icons.

Repository (GitHub)
View/report issues

Topics

#avatar #profile #image #widget #picture

Documentation

API reference

License

MIT (license)

Dependencies

cached_network_image, flutter

More

Packages that depend on my_profile_avatar