android_glide_view 0.0.4 copy "android_glide_view: ^0.0.4" to clipboard
android_glide_view: ^0.0.4 copied to clipboard

PlatformAndroid

A Flutter plugin for displaying images with Glide.

Android Glide View #

This Flutter plugin uses the Glide library for image loading on Android.

Glide is licensed under the BSD 2-Clause License. Copyright (c) 2014 Google Inc. All rights reserved.

For more information, see: https://github.com/bumptech/glide

A Flutter plugin that provides efficient image loading and caching using the Glide image loading library on Android. This plugin offers a native Android view that seamlessly integrates with Flutter widgets, providing powerful image loading capabilities with automatic caching, memory management, and various image transformations.

Features #

  • 🚀 High Performance: Native Android implementation using Glide for optimal performance
  • 🖼️ Multiple Image Sources: Support for network URLs, local file paths, and content URIs
  • 💾 Automatic Caching: Built-in disk and memory caching for faster image loading
  • ✂️ Image Transformations: Center crop, fit center, and circle crop transformations
  • 🔄 Memory Management: Automatic memory optimization and cleanup
  • 📱 Platform Integration: Seamless integration with Flutter widgets

Installation #

Add android_glide_view to your pubspec.yaml file:

dependencies:
  android_glide_view: ^0.0.1

Usage #

Basic Usage #

import 'package:android_glide_view/android_glide_view.dart';

GlideView(
  imageUri: 'https://example.com/image.jpg',
)

Advanced Usage #

GlideView(
  imageUri: 'https://example.com/image.jpg',
  cropType: CropType.centerCrop,
)

Different Image Sources #

// Network image
GlideView(
  imageUri: 'https://example.com/image.jpg',
  cropType: CropType.fitCenter,
)

// Local file
GlideView(
  imageUri: '/storage/emulated/0/DCIM/image.jpg',
  cropType: CropType.circleCrop,
)

// Content URI
GlideView(
  imageUri: 'content://media/external/images/media/123',
  cropType: CropType.centerCrop,
)

API Reference #

GlideView Widget #

The main widget for displaying images with Glide.

Constructor

const GlideView({
  Key? key,
  required String imageUri,
  CropType? cropType,
})

Parameters

Parameter Type Required Description
key Key? No Widget key for identification and testing
imageUri String Yes The URI of the image to display
cropType CropType? No Image transformation type

CropType Enum #

Defines the available image transformation types.

enum CropType {
  centerCrop,    // Scales image to fill bounds, cropping if necessary
  fitCenter,     // Scales image to fit within bounds while maintaining aspect ratio
  circleCrop,    // Crops image to a circle
}

CropType.centerCrop

Scales the image to fill the entire view while maintaining its aspect ratio. If the image doesn't match the view's aspect ratio, it will be cropped.

CropType.fitCenter

Scales the image to fit within the view bounds while maintaining its aspect ratio. The entire image will be visible.

CropType.circleCrop

Crops the image to a perfect circle, useful for profile pictures and avatars.

Examples #

class ImageGallery extends StatelessWidget {
  final List<String> imageUrls = [
    'https://example.com/image1.jpg',
    'https://example.com/image2.jpg',
    'https://example.com/image3.jpg',
  ];

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        crossAxisSpacing: 8,
        mainAxisSpacing: 8,
      ),
      itemCount: imageUrls.length,
      itemBuilder: (context, index) {
        return GlideView(
          imageUri: imageUrls[index],
          cropType: CropType.centerCrop,
        );
      },
    );
  }
}

Profile Picture #

GlideView(
  imageUri: 'https://example.com/profile.jpg',
  cropType: CropType.circleCrop,
)

Responsive Image #

Container(
  width: double.infinity,
  height: 200,
  child: GlideView(
    imageUri: 'https://example.com/banner.jpg',
    cropType: CropType.fitCenter,
  ),
)

Performance Considerations #

  • Caching: The plugin automatically caches images both in memory and on disk for optimal performance
  • Memory Management: Glide handles memory optimization automatically
  • Network Efficiency: Images are loaded efficiently with proper error handling
  • Placeholder Support: Built-in placeholder images while loading

Note: This plugin is specifically designed for Android and leverages the Glide image loading library for optimal performance and features.

License #

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