import 'package:boilerplate/core/di/injection_init.dart';
import 'package:boilerplate/domain/entities/flavor/flavor_data.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

class IPMImage extends StatelessWidget {
  final String url;
  final BoxFit fit;

  const IPMImage({
    Key? key,
    required this.url,
    this.fit = BoxFit.contain,
  }) : super(key: key);

  _getUrl() {
    // print('geturl ${url}');
    // print(url.contains('https'));
    // print(url.contains('http'));
    if (url.contains('http') || url.contains('https')) {
      return url;
    } else {
      return getIt.get<AppFlavorData>().baseUrl + "/$url";
    }
  }

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: _getUrl(),
      fit: fit,
      errorWidget: (context, error, stackTrace) => Container(
        color: Colors.grey,
      ),
    );
  }
}
