A Flutter package providing a simple ImageProvider that generates a solid-color image. This is particularly useful for debugging UI layouts, placeholders, or testing image loading mechanisms without needing actual image assets.
- Generates a solid-color image on the fly.
- Customizable color, width, and height.
- Extends
ImageProvider, making it compatible withImage.image,DecorationImage, etc. - Lightweight and efficient for debugging purposes.
Add this to your pubspec.yaml file:
dependencies:
solid_color_image_provider: ^0.0.1 # Or the latest versionThen run flutter pub get.
Import the package:
import 'package:solid_color_image_provider/solid_color_image_provider.dart';Use it with Image.image or any widget that accepts an ImageProvider:
import 'package:flutter/material.dart';
import 'package:solid_color_image_provider/solid_color_image_provider.dart';
// A red 50x50 image (default)
Image(image: SolidColorImageProvider());
// A blue 100x200 image
Image(
image: SolidColorImageProvider(
color: Colors.blue,
width: 100,
height: 200,
),
);
// As a background image in a Container
Container(
width: 300,
height: 150,
decoration: BoxDecoration(
image: DecorationImage(
image: SolidColorImageProvider(
color: Colors.green,
width: 300, // Should match container dimensions for best results
height: 150,
),
fit: BoxFit.cover,
),
),
child: const Center(child: Text('Hello', style: TextStyle(color: Colors.white))),
);Contributions are welcome! Please feel free to open an issue or submit a pull request.