Skip to content

Latest commit

 

History

History
129 lines (106 loc) · 3.94 KB

File metadata and controls

129 lines (106 loc) · 3.94 KB

Image Loading Improvements

Overview

This document describes the recent improvements made to the slideshow image loading experience.

Changes Implemented

1. Blurred Placeholder Instead of Loader

What changed:

  • Replaced the circular progress indicator with a blurred version of the image
  • The placeholder shows a low-resolution (100x100px) version of the image with a 20px blur effect
  • This provides a better visual experience while the full-resolution image loads

Benefits:

  • Users see a preview of the image immediately
  • More elegant and professional appearance
  • Reduces perceived loading time
  • Maintains visual continuity

2. Image Precaching

What changed:

  • Implemented automatic precaching of the next 3 images in the slideshow
  • Precaching happens:
    • When slides are first loaded
    • After each slide transition (next or previous)
  • Uses Flutter's precacheImage() with CachedNetworkImageProvider

Benefits:

  • Images are ready before they're displayed
  • Smoother transitions between slides
  • Better user experience, especially on slower networks
  • Reduces waiting time between slides

Technical Details

Blurred Placeholder Implementation

Widget _buildBlurredPlaceholder(String url) {
  return Stack(
    fit: StackFit.expand,
    children: [
      CachedNetworkImage(
        imageUrl: url,
        fit: BoxFit.cover,
        memCacheWidth: 100,  // Low resolution for quick loading
        memCacheHeight: 100,
        imageBuilder: (context, imageProvider) {
          return Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: imageProvider,
                fit: BoxFit.cover,
              ),
            ),
            child: BackdropFilter(
              filter: ui.ImageFilter.blur(sigmaX: 20.0, sigmaY: 20.0),
              child: Container(
                color: Colors.black.withValues(alpha: 0.3),
              ),
            ),
          );
        },
      ),
    ],
  );
}

Precaching Implementation

void _precacheNextImages() {
  if (_slides.isEmpty || !mounted) return;

  for (int i = 1; i <= _precacheCount; i++) {
    final nextIndex = (_currentIndex + i) % _slides.length;
    final imageUrl = _slides[nextIndex].imageUrl;
    
    precacheImage(
      CachedNetworkImageProvider(imageUrl),
      context,
    ).catchError((error) {
      debugPrint('Error precaching image at index $nextIndex: $error');
    });
  }
}

Configuration

Adjustable Parameters

  • Precache count: Currently set to 3 images ahead

    • Can be modified via _precacheCount constant
    • Higher values use more memory but provide smoother experience
  • Blur intensity: Currently set to 20px (sigmaX and sigmaY)

    • Can be adjusted in _buildBlurredPlaceholder()
    • Higher values create more blur
  • Placeholder resolution: Currently 100x100px

    • Can be adjusted via memCacheWidth and memCacheHeight
    • Lower values load faster but may look more pixelated

Performance Considerations

Memory Usage

  • Precaching 3 images at 1920x1080 resolution uses approximately 20-30MB of memory
  • Blurred placeholders use minimal memory (100x100px = ~30KB per image)
  • cached_network_image handles disk caching automatically

Network Usage

  • Images are downloaded once and cached on disk
  • Precaching happens in the background without blocking UI
  • Failed precache attempts are logged but don't affect user experience

Testing Recommendations

  1. Slow Network: Test on 3G/4G to verify blurred placeholders appear quickly
  2. Fast Network: Verify smooth transitions with precaching
  3. Memory: Monitor memory usage with multiple slides
  4. Edge Cases: Test with network interruptions and failed image loads

Future Improvements

Possible enhancements:

  • Adaptive precaching based on network speed
  • Progressive image loading (low-res → high-res)
  • Preload images in both directions (forward and backward)
  • Smart precaching based on user behavior