import 'package:cached_network_image/cached_network_image.dart';
import 'package:e_commerce_training/res/R.dart';
import 'package:e_commerce_training/src/model/response/featured_category.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CategoryWidget extends StatelessWidget {
  const CategoryWidget({
    Key? key,
    required this.item,
    required this.voidCallback,
  }) : super(key: key);

  final FeaturedCategory item;
  final VoidCallback voidCallback;

  @override
  Widget build(BuildContext context) {
    double width = ((MediaQuery.of(context).size.width - 20) / 2);
    return Container(
      width: width,
      child: InkWell(
        onTap: voidCallback,
        child: AspectRatio(
          aspectRatio: 1,
          child: Card(
            child: Container(
              alignment: Alignment.bottomCenter,
              child: Container(
                alignment: Alignment.center,
                color: Color.fromRGBO(0, 0, 0, 0.4),
                height: 70.h,
                width: double.infinity,
                child: Text(
                  item.name ?? "",
                  style: TextStyle(
                    color: R.color.white,
                    fontWeight: FontWeight.w500,
                    fontSize: 30.sp,
                  ),
                  textAlign: TextAlign.center,
                  maxLines: 1,
                ),
              ),
              decoration: BoxDecoration(
                image: DecorationImage(image: CachedNetworkImageProvider(item.image!), fit: BoxFit.fill),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
