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

class TabCustomGradientIndicator extends Decoration {
  @override
  BoxPainter createBoxPainter([VoidCallback? onChanged]) {
    return _TabCustomGradientIndicatorPainter();
  }
}

class _TabCustomGradientIndicatorPainter extends BoxPainter {
  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    final double indicatorWidth = 16.0.w;
    final double indicatorHeight = 4.0.h;
    final double dx =
        offset.dx + (configuration.size!.width - indicatorWidth) / 2;
    final double dy =
        offset.dy + configuration.size!.height - indicatorHeight - 2;
    final Rect rect = Rect.fromLTWH(dx, dy, indicatorWidth, indicatorHeight);
    final RRect rRect = RRect.fromRectAndRadius(rect, Radius.circular(4));

    final Paint paint =
        Paint()
          ..shader = LinearGradient(
            begin: Alignment(0.04, 0.21),
            end: Alignment(0.98, 0.76),
            colors: [Color(0xFF7D46FC), Color(0xFFBC87FF)],
          ).createShader(rect);

    canvas.drawRRect(rRect, paint);
  }
}
