content: import 'package:flutter/material.dart';
  
  class NextEpisodeButton extends StatefulWidget {
    final VoidCallback onTap;
    final double progress;
  
    const NextEpisodeButton({
      Key? key,
      required this.onTap,
      required this.progress,
    }) : super(key: key);
  
    @override
    State<NextEpisodeButton> createState() => _NextEpisodeButtonState();
  }
  
  class _NextEpisodeButtonState extends State<NextEpisodeButton> with SingleTickerProviderStateMixin {
    late AnimationController _controller;
    late Animation<double> _fadeAnimation;
  
    @override
    void initState() {
      super.initState();
      _controller = AnimationController(
        duration: const Duration(milliseconds: 500),
        vsync: this,
      );
  
      _fadeAnimation = Tween<double>(
        begin: 0.0,
        end: 1.0,
      ).animate(CurvedAnimation(
        parent: _controller,
        curve: Curves.easeInOut,
      ));
  
      if (widget.progress >= 0.9) {
        _controller.forward();
      }
    }
  
    @override
    void didUpdateWidget(NextEpisodeButton oldWidget) {
      super.didUpdateWidget(oldWidget);
      if (widget.progress >= 0.9 && !_controller.isCompleted) {
        _controller.forward();
      } else if (widget.progress < 0.9 && !_controller.isDismissed) {
        _controller.reverse();
      }
    }
  
    @override
    void dispose() {
      _controller.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return FadeTransition(
        opacity: _fadeAnimation,
        child: Opacity(
          opacity: widget.progress >= 0.9 ? 1.0 : 0.3, // Reduced opacity when not near end
          child: Material(
            color: Colors.transparent,
            child: InkWell(
              onTap: widget.progress >= 0.9 ? widget.onTap : null, // Only enable when near end
              borderRadius: BorderRadius.circular(12),
              child: Container(
                padding: const EdgeInsets.all(16),
                decoration: BoxDecoration(
                  color: Theme.of(context).colorScheme.primary,
                  borderRadius: BorderRadius.circular(12),
                  boxShadow: [
                    BoxShadow(
                      color: Theme.of(context).colorScheme.primary.withOpacity(0.3),
                      blurRadius: 8,
                      offset: const Offset(0, 2),
                    ),
                  ],
                ),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Stack(
                      alignment: Alignment.center,
                      children: [
                        SizedBox(
                          width: 32,
                          height: 32,
                          child: CircularProgressIndicator(
                            value: widget.progress,
                            backgroundColor: Colors.white24,
                            valueColor: const AlwaysStoppedAnimation<Color>(Colors.white),
                            strokeWidth: 2,
                          ),
                        ),
                        const Icon(
                          Icons.play_arrow_rounded,
                          color: Colors.white,
                          size: 20,
                        ),
                      ],
                    ),
                    const SizedBox(width: 12),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        const Text(
                          'Up Next',
                          style: TextStyle(
                            color: Colors.white70,
                            fontSize: 12,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                        const SizedBox(height: 2),
                        const Text(
                          'Next Episode',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ],
                    ),
                    const SizedBox(width: 16),
                    const Icon(
                      Icons.arrow_forward_ios_rounded,
                      color: Colors.white70,
                      size: 16,
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
    }
  }
  