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

class ImageLoader extends StatelessWidget {
  final String? url;
  final BoxFit? boxFit;
  final Color? color;
  final Alignment? alignment;
  final double? width;
  final double? height;
  final bool showDefaultIcon;

  const ImageLoader({Key? key, required this.url, this.boxFit, this.color, this.alignment, this.width, this.height, this.showDefaultIcon = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: url ?? "",
      fit: boxFit ?? BoxFit.cover,
      alignment: Alignment.center,
      width: width,
      height: height,
      placeholder: (context, url) => const Center(child: CircularProgressIndicator()),
      errorWidget: (context, url, error) => Icon(showDefaultIcon ? Icons.image_outlined : Icons.broken_image_rounded),
    );
  }
}
