image_builder 1.1.4 copy "image_builder: ^1.1.4" to clipboard
image_builder: ^1.1.4 copied to clipboard

A comprehensive Flutter package for handling network images, SVGs, local assets, file images, and memory images with caching and error handling.

ImageBuilder #

A comprehensive Flutter package for handling various image types including network images, SVGs, local assets, file images, and memory images with advanced caching, platform-adaptive loading indicators, and robust error handling.

โœจ Features #

  • ๐Ÿ–ผ๏ธ Multi-format support: PNG, JPG, JPEG, WEBP, SVG
  • ๐ŸŒ Network image loading: Built-in caching with CachedNetworkImage
  • ๐Ÿ“ฑ Local asset support: Seamless integration with Flutter assets
  • ๐Ÿ“ File image support: Load images directly from device files
  • ๐Ÿ’พ Memory image support: Display images from Uint8List byte data
  • ๐ŸŽจ SVG customization: Color tinting and scaling for vector graphics
  • โšก Robust error handling: Graceful fallbacks and custom error widgets
  • ๐Ÿ”„ Platform-adaptive loading:
    • iOS/macOS: Native CupertinoActivityIndicator
    • Android/Web: Material Design CircularProgressIndicator
  • ๐ŸŽฏ Loading color customization: Custom colors for loading indicators
  • ๐Ÿ“ Flexible sizing: Individual width/height or unified size parameter
  • ๐Ÿ›ก๏ธ Production-ready: Comprehensive error handling prevents crashes
  • ๐Ÿงช Well-tested: Extensive test suite with 25+ test cases covering all functionality

๐Ÿ“ฆ Installation #

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

dependencies:
  image_builder: ^1.1.1

Then run:

flutter pub get

๐Ÿš€ Quick Start #

Import the package:

import 'package:image_builder/image_builder.dart';

Basic Usage #

// Display any type of image (network, asset, SVG)
ImageBuilder('assets/images/logo.png')

// Display a network image with adaptive loading
ImageBuilder('https://example.com/image.jpg')

๐Ÿ“ Custom Sizing #

// Using individual width and height
ImageBuilder(
  'assets/images/logo.svg',
  width: 100,
  height: 100,
  fit: BoxFit.cover,
)

// Using unified size (sets both width and height)
ImageBuilder(
  'assets/images/icon.png',
  size: 50,
)

๐ŸŽจ SVG Color Customization #

// Tint SVG with custom colors
ImageBuilder(
  'assets/icons/heart.svg',
  size: 24,
  color: Colors.red, // Apply red tint to SVG
)

๐Ÿ“ File Images #

import 'dart:io';

// Display image from device file
final File imageFile = File('/path/to/image.jpg');
ImageBuilder.file(
  imageFile,
  width: 200,
  height: 150,
  fit: BoxFit.cover,
)

๐Ÿ’พ Memory Images #

import 'dart:typed_data';

// Display image from memory bytes
final Uint8List imageBytes = await getImageBytes();
ImageBuilder.memory(
  imageBytes,
  width: 200,
  height: 150,
  fit: BoxFit.cover,
)

๐Ÿ”„ Platform-Adaptive Loading #

The package automatically uses platform-appropriate loading indicators:

// Automatic platform detection
ImageBuilder(
  'https://example.com/image.jpg',
  width: 200,
  height: 200,
  useAdaptiveLoading: true, // Default: true
)

// Force Material Design loading (all platforms)
ImageBuilder(
  'https://example.com/image.jpg',
  width: 200,
  height: 200,
  useAdaptiveLoading: false,
)

Platform Behavior:

  • iOS/macOS: Uses CupertinoActivityIndicator for native look
  • Android/Web/Others: Uses CircularProgressIndicator for Material Design

๐ŸŽฏ Custom Loading Colors #

Personalize your loading indicators with custom colors:

// Blue loading indicator
ImageBuilder(
  'https://example.com/large-image.jpg',
  width: 200,
  height: 200,
  useAdaptiveLoading: true,
  loadingColor: Colors.blue, // Works on both Cupertino and Material indicators
)

// Custom color with hex value
ImageBuilder(
  'https://example.com/image.jpg',
  width: 200,
  height: 200,
  loadingColor: Color(0xFF6B46C1), // Custom purple
)

๐Ÿ›ก๏ธ Advanced Error Handling #

ImageBuilder(
  'https://example.com/image.jpg',
  width: 200,
  height: 200,
  placeholder: Container(
    color: Colors.grey[200],
    child: const CircularProgressIndicator(),
  ),
  errorWidget: Container(
    color: Colors.red[100],
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Icon(Icons.error, color: Colors.red),
        Text('Failed to load image'),
      ],
    ),
  ),
)

๐Ÿ“š Complete Example #

Here's a comprehensive example showcasing all major features:

import 'package:flutter/material.dart';
import 'package:image_builder/image_builder.dart';

class ImageGallery extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('ImageBuilder Examples')),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(16),
        child: Column(
          children: [
            // Network image with adaptive loading
            ImageBuilder(
              'https://picsum.photos/300/200',
              width: 300,
              height: 200,
              fit: BoxFit.cover,
              loadingColor: Colors.blue,
            ),
            
            SizedBox(height: 20),
            
            // SVG with custom color
            ImageBuilder(
              'assets/icons/star.svg',
              size: 60,
              color: Colors.amber,
            ),
            
            SizedBox(height: 20),
            
            // Local image with error handling
            ImageBuilder(
              'assets/images/photo.png',
              width: 200,
              height: 150,
              fit: BoxFit.cover,
              errorWidget: Container(
                width: 200,
                height: 150,
                color: Colors.grey[200],
                child: Icon(Icons.broken_image, size: 50),
              ),
            ),

            SizedBox(height: 20),
            
            // File image
            ImageBuilder.file(
              File('/path/to/device/image.jpg'),
              width: 200,
              height: 150,
              fit: BoxFit.cover,
            ),

            SizedBox(height: 20),
            
            // Memory image
            ImageBuilder.memory(
              imageBytes, // Uint8List
              width: 200,
              height: 150,
              fit: BoxFit.cover,
            ),
          ],
        ),
      ),
    );
  }
}

๐ŸŽฎ Interactive Example App #

The package includes a comprehensive example app that demonstrates all features including device image upload functionality:

  • Gallery Selection: Pick images from your device's photo library
  • Camera Capture: Take new photos directly from the camera
  • Cross-Platform: Works on iOS, Android, macOS, and other Flutter-supported platforms
  • Real-time Preview: See ImageBuilder.file() in action with your own images

To run the example app:

cd example
flutter run

The example app showcases:

  • Network image loading with adaptive indicators
  • SVG rendering with color customization
  • Memory image display from asset bytes (using photo.jpg)
  • Cross-platform file picker using ImageBuilder.file() (works on Mobile, Desktop & Web)
  • Device image upload using ImageBuilder.file() (gallery/camera selection for mobile)
  • Error handling and fallback widgets
  • All supported image formats

Platform Support:

  • Mobile (iOS/Android): Gallery selection using ImageBuilder.file()
  • Desktop (macOS/Windows/Linux): Native file picker using ImageBuilder.file()
  • Web: File selection with automatic fallback to ImageBuilder.memory()

Smart Platform Detection: The example app automatically shows the appropriate UI based on your platform - file picker on desktop/web or gallery selection on mobile.

Perfect for testing the package capabilities and understanding implementation patterns!

๐Ÿ“– API Reference #

ImageBuilder Constructors #

The ImageBuilder widget provides multiple constructors for different image sources.

Default Constructor (Path-based)

ImageBuilder(
  String path, {
  Key? key,
  double? width,
  double? height,
  double? size,
  Color? color,
  BoxFit fit = BoxFit.contain,
  Widget? placeholder,
  Widget? errorWidget,
  Duration? maxCacheAge,
  int? maxCacheSizeBytes,
  bool useAdaptiveLoading = true,
  Color? loadingColor,
})

File Constructor

ImageBuilder.file(
  File file, {
  Key? key,
  double? width,
  double? height,
  double? size,
  Color? color,
  BoxFit fit = BoxFit.contain,
  Widget? placeholder,
  Widget? errorWidget,
  Duration? maxCacheAge,
  int? maxCacheSizeBytes,
  bool useAdaptiveLoading = true,
  Color? loadingColor,
})

Memory Constructor

ImageBuilder.memory(
  Uint8List bytes, {
  Key? key,
  double? width,
  double? height,
  double? size,
  Color? color,
  BoxFit fit = BoxFit.contain,
  Widget? placeholder,
  Widget? errorWidget,
  Duration? maxCacheAge,
  int? maxCacheSizeBytes,
  bool useAdaptiveLoading = true,
  Color? loadingColor,
})

Parameters #

Parameter Type Description Default
path String Required for default constructor. Image path or URL (network, asset, or local) -
file File Required for file constructor. File object to load image from -
bytes Uint8List Required for memory constructor. Image data as bytes -
width double? Image width in logical pixels (ignored if size provided) null
height double? Image height in logical pixels (ignored if size provided) null
size double? Sets both width and height to same value null
color Color? Tint color for SVG images null
fit BoxFit How image should be inscribed into layout space BoxFit.contain
placeholder Widget? Custom widget shown while loading (overrides adaptive loading) null
errorWidget Widget? Custom widget shown when loading fails null
maxCacheAge Duration? Maximum cache duration for network images null
maxCacheSizeBytes int? Maximum cache size in bytes null
useAdaptiveLoading bool Enable platform-adaptive loading indicators true
loadingColor Color? Custom color for adaptive loading indicators null

๐ŸŽฏ Supported Image Formats #

Network Images #

  • All formats supported by Flutter's network image loading
  • HTTPS/HTTP protocols supported
  • Automatic caching with CachedNetworkImage
  • Custom cache duration and size limits

Local Assets #

  • PNG, JPG, JPEG: Standard raster formats
  • WEBP: Modern efficient format
  • Assets folder integration with pubspec.yaml

Vector Graphics #

  • SVG: Scalable vector graphics with color customization
  • Color tinting: Apply any color to SVG elements
  • Perfect scaling: No quality loss at any size

๐Ÿ”ง Platform Support #

Platform Adaptive Loading Network Images Local Assets SVG Support
iOS โœ… Cupertino โœ… โœ… โœ…
macOS โœ… Cupertino โœ… โœ… โœ…
Android โœ… Material โœ… โœ… โœ…
Web โœ… Material โœ… โœ… โœ…
Windows โœ… Material โœ… โœ… โœ…
Linux โœ… Material โœ… โœ… โœ…

*macOS requires network entitlements for network images

๐Ÿ”— Dependencies #

This package uses these well-maintained dependencies:

๐Ÿงช Testing #

The package includes comprehensive tests covering:

  • โœ… Platform-adaptive loading behavior across all platforms
  • โœ… Loading color customization functionality
  • โœ… Network error handling and recovery
  • โœ… File image loading with proper error handling
  • โœ… Memory image display from Uint8List data
  • โœ… Graceful error states without crashes
  • โœ… Cross-platform compatibility testing
  • โœ… SVG color tinting and rendering
  • โœ… Robust widget construction for all image types

Run tests with:

flutter test

๐Ÿค 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.

๐Ÿ“„ License #

MIT License - see the LICENSE file for details.

3
likes
160
points
219
downloads

Publisher

unverified uploader

Weekly Downloads

A comprehensive Flutter package for handling network images, SVGs, local assets, file images, and memory images with caching and error handling.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

cached_network_image, flutter, flutter_svg

More

Packages that depend on image_builder