flutter_cors_image 0.1.6 copy "flutter_cors_image: ^0.1.6" to clipboard
flutter_cors_image: ^0.1.6 copied to clipboard

A Flutter package that provides image loading solutions for handling CORS issues and problematic images on web platforms.

Flutter CORS Image #

pub package

A Flutter package that provides image loading solutions for handling CORS issues and problematic images on web platforms.

Features #

This package offers two different approaches to solve image loading issues:

1. CustomNetworkImage #

This approach follows this strategy:

  1. First, try to load the image using Flutter's normal Image.network widget
  2. If that fails on web platforms, automatically fall back to using an HTML img tag
  3. On native platforms, fall back to using ExtendedImage for additional compatibility

This is a more robust solution that:

  1. Uses an iframe to load the image directly, completely bypassing CORS restrictions
  2. Works reliably with images that have unusual formats or server configurations
  3. Falls back to a standard Image.network on non-web platforms

Installation #

Add the dependency to your pubspec.yaml:

dependencies:
  flutter_cors_image: ^0.1.0

Usage #

Import the package:

import 'package:flutter_cors_image/flutter_cors_image.dart';

Using CustomNetworkImage: #

CustomNetworkImage(
  url: 'https://example.com/image.jpg',
  width: 300,
  height: 200,
  fit: BoxFit.cover,
)
ProxyNetworkImage(
  url: 'https://example.com/image-with-cors-issues.jpg',
  width: 300,
  height: 200,
  fit: BoxFit.cover,
)

Both widgets support all standard parameters from Image.network:

ProxyNetworkImage(
  url: 'https://example.com/image.jpg',
  width: 300,
  height: 200,
  fit: BoxFit.cover,
  // Standard Image.network parameters
  headers: {'Authorization': 'Bearer token'},
  cacheWidth: 600,
  cacheHeight: 400,
  scale: 1.0,
  // ...and more
)

Example #

Here's an example comparing both approaches:

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

class ExampleScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter CORS Image Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // ProxyNetworkImage (recommended)
            Text('ProxyNetworkImage (Recommended)'),
            ProxyNetworkImage(
              url: 'https://example.com/image-with-cors-issues.jpg',
              width: 300,
              height: 200,
            ),
            
            SizedBox(height: 20),
            
            // CustomNetworkImage
            Text('CustomNetworkImage'),
            CustomNetworkImage(
              url: 'https://example.com/image-with-cors-issues.jpg',
              width: 300,
              height: 200,
            ),
          ],
        ),
      ),
    );
  }
}

Real-world Example #

The ProxyNetworkImage works with images like:

  • https://example.com/image-with-cors-issues.jpg

Which typically fails with standard Flutter Image.network due to CORS restrictions.

License #

MIT

0
likes
130
points
232
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package that provides image loading solutions for handling CORS issues and problematic images on web platforms.

Repository (GitHub)
View/report issues

Topics

#image #cors #web #html

Documentation

API reference

License

MIT (license)

Dependencies

cupertino_icons, extended_image, ffmpeg_kit_flutter, flutter, flutter_web_plugins, http, image, intl, path_provider

More

Packages that depend on flutter_cors_image