import 'package:flutter/cupertino.dart';

class FixedSizeTabIndicator extends Decoration {
  final double width; // Fixed width
  final double height; // Indicator height
  final double radius; // Corner radius
  final Color color; // Indicator color

  const FixedSizeTabIndicator({
    required this.width,
    required this.height,
    required this.radius,
    required this.color,
  });

  @override
  BoxPainter createBoxPainter([VoidCallback? onChanged]) {
    return _CustomPainter(this, onChanged);
  }
}

class _CustomPainter extends BoxPainter {
  final FixedSizeTabIndicator decoration;

  _CustomPainter(this.decoration, VoidCallback? onChanged) : super(onChanged);

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    final Paint paint = Paint();
    paint.color = decoration.color;
    paint.style = PaintingStyle.fill;

    final double xPos =
        offset.dx + (configuration.size!.width / 2) - (decoration.width / 2);
    final double yPos = configuration.size!.height - decoration.height;

    final Rect rect =
        Rect.fromLTWH(xPos, yPos, decoration.width, decoration.height);
    final RRect rRect = RRect.fromRectAndRadius(
        rect, Radius.circular(decoration.radius)); // Rounded corners

    canvas.drawRRect(rRect, paint);
  }
}
