imagePreviewImage function

Widget imagePreviewImage(
  1. String imagePath, {
  2. required String fallbackTitle,
  3. BoxFit fit = BoxFit.contain,
  4. Color? gradientStart,
  5. Color? gradientEnd,
  6. Color? accentColor,
  7. Color? iconColor,
})

Builds a preview image for imagePath, routed through UIImage so it inherits the kit's caching, UIImageScope builders, and error handling.

Falls back to imagePreviewPlaceholder for empty paths and load failures. When the color overrides are omitted the placeholder resolves its palette from the ambient Theme.

Implementation

Widget imagePreviewImage(
  String imagePath, {
  required String fallbackTitle,
  BoxFit fit = BoxFit.contain,
  Color? gradientStart,
  Color? gradientEnd,
  Color? accentColor,
  Color? iconColor,
}) {
  final trimmed = imagePath.trim();

  return Builder(
    builder: (context) {
      final placeholder = imagePreviewPlaceholder(
        context,
        fallbackTitle,
        gradientStart: gradientStart,
        gradientEnd: gradientEnd,
        accentColor: accentColor,
        iconColor: iconColor,
      );

      if (trimmed.isEmpty) return placeholder;

      final isNetwork =
          trimmed.startsWith('http://') || trimmed.startsWith('https://');

      return UIImage(
        trimmed,
        isAsset: !isNetwork,
        fit: fit,
        width: double.infinity,
        height: double.infinity,
        alignment: Alignment.center,
        placeholder: placeholder,
        fallback: placeholder,
      );
    },
  );
}