mirrored_repositories/borgia_flutter_app/lib
import 'dart:io';
import 'package:borgiaflutterapp/utils/dimensions.dart';
import 'package:flutter/material.dart';

class FlickerText extends StatefulWidget {
  final Color color;
  final String text;
  final bool shouldFlicker;
  const FlickerText({Key? key, required this.color, required this.text, required this.shouldFlicker}) : super(key: key);
  @override
  FlickerTextState createState() => FlickerTextState();
}

class FlickerTextState extends State<FlickerText> with TickerProviderStateMixin {
  late AnimationController animation;
  late Animation<double> _fadeInFadeOut;

  @override
  void initState() {
    super.initState();
    animation = AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 200),
    );
    _fadeInFadeOut = Tween<double>(begin: 1.0, end: 0.2).animate(animation);

    animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        animation.reverse();
      } else if (status == AnimationStatus.dismissed) {
        sleep(const Duration(milliseconds: 500));
        animation.forward();
      }
    });
    animation.forward();
  }

  @override
  void dispose() {
    animation.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    TextStyle strokeStyle = TextStyle(
      letterSpacing: 5,
      fontSize: Dimensions.height20 * 3,
      foreground: Paint()
        ..style = PaintingStyle.stroke
        ..strokeWidth = 2
        ..color = widget.color,
      fontFamily: "RetroSignature",
    );
    TextStyle glowStyle = TextStyle(
      letterSpacing: 5,
      fontSize: Dimensions.height20 * 3,
      shadows: [
        BoxShadow(
          color: widget.color,
          blurRadius: 1.0,
          spreadRadius: 1.0,
        ),
        BoxShadow(
          color: widget.color,
          blurRadius: 30.0,
          spreadRadius: 30.0,
        ),
        BoxShadow(
          color: widget.color,
          blurRadius: 30.0,
          spreadRadius: 2.0,
        ),
        BoxShadow(
          color: widget.color,
          blurRadius: 200.0,
          spreadRadius: 200.0,
        ),
      ],
      color: Theme.of(context).colorScheme.surface,
      fontFamily: "RetroSignature",
    );
    return widget.shouldFlicker
        ? FadeTransition(
            opacity: _fadeInFadeOut,
            child: Stack(
              alignment: Alignment.center,
              children: [
                Text(widget.text, textAlign: TextAlign.center, style: strokeStyle),
                Text(widget.text, textAlign: TextAlign.center, style: glowStyle),
              ],
            ),
          )
        : Stack(
            alignment: Alignment.center,
            children: [
              Text(widget.text, textAlign: TextAlign.center, style: strokeStyle),
              Text(widget.text, textAlign: TextAlign.center, style: glowStyle),
            ],
          );
  }
}
