import 'package:flutter/cupertino.dart';

/// 渐变色文字
class GradientText extends StatelessWidget {
  /// 渐变颜色参数
  final List<Color> colors;

  final AlignmentGeometry begin;
  final AlignmentGeometry end;

  final Widget child;

  const GradientText({
    super.key,
    required this.colors,
    this.begin = Alignment.centerLeft,
    this.end = Alignment.centerRight,
    required this.child,
  });

  @override
  Widget build(BuildContext context) {
    return ShaderMask(
      // 线性渐变
      shaderCallback:
          (bounds) => LinearGradient(
            colors: colors,
            begin: begin,
            end: end,
          ).createShader(bounds),
      blendMode: BlendMode.srcIn,
      // 内容
      child: child,
    );
  }
}
