
import 'package:flutter/widgets.dart';

class LinearGradientText extends StatelessWidget {
  final AlignmentGeometry begin;
  final AlignmentGeometry end;
  final List<Color> colors;
  Widget child;

  LinearGradientText({
    Key? key,
    required this.colors,
    required this.child,
    this.begin = Alignment.topCenter,
    this.end = Alignment.bottomCenter,
  }) : super(key: key);

  Shader _linearGradient(Rect bounds) {
    Gradient gradient = LinearGradient(colors: colors, begin: begin, end: end);
    return gradient.createShader(bounds);
  }

  @override
  Widget build(BuildContext context) {
    return ShaderMask(
      blendMode: BlendMode.srcIn,
      shaderCallback: (bounds) => _linearGradient(bounds),
      child: child,
    );
  }
}
