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

import '../utils/color_utils.dart';

class CacheNetWorkCustom extends StatelessWidget {
  const CacheNetWorkCustom({Key? key, required this.urlImage})
      : super(key: key);
  final String urlImage;

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: urlImage,
      imageBuilder: (context, imageProvider) => Container(
        alignment: Alignment.center,
        decoration: BoxDecoration(
          image: DecorationImage(
            image: imageProvider,
            fit: BoxFit.fill,
          ),
        ),
      ),
      placeholder: (context, url) => const Center(
        child: CupertinoActivityIndicator(
          color: ColorUtils.PRIMARY_COLOR,
        ),
      ),
      color: ColorUtils.PRIMARY_COLOR,
      errorWidget: (context, url, error) => Image.asset(
        "assets/images/background_app_betting.jpg",
      ),
    );
  }
}

class CacheNetWorkCustomBanner extends StatelessWidget {
  const CacheNetWorkCustomBanner({Key? key, required this.urlImage})
      : super(key: key);
  final String urlImage;

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: urlImage,
      imageBuilder: (context, imageProvider) => Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          image: DecorationImage(
            image: imageProvider,
            fit: BoxFit.cover,
          ),
        ),
      ),
      placeholder: (context, url) =>
          Center(child: Image.asset('assets/images/loading.gif')),
      color: ColorUtils.PRIMARY_COLOR,
      errorWidget: (context, url, error) => Image.asset(
        "assets/images/background_app_betting.jpg",
      ),
    );
  }
}
