content: import 'package:flutter/material.dart';
  import 'package:video_player/video_player.dart';
  
  class VideoWidget extends StatefulWidget {
    final String url;
    final bool play;
  
    const VideoWidget({Key? key, required this.url, required this.play})
        : super(key: key);
    @override
    _VideoWidgetState createState() => _VideoWidgetState();
  }
  
  class _VideoWidgetState extends State<VideoWidget> {
    late VideoPlayerController _controller;
    late Future<void> _initializeVideoPlayerFuture;
  
    @override
    void initState() {
      super.initState();
      _controller = VideoPlayerController.network(widget.url);
      _initializeVideoPlayerFuture = _controller.initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });
  
      if (widget.play) {
        _controller.play();
        _controller.setLooping(true);
      }
    }
  
    @override
    void didUpdateWidget(VideoWidget oldWidget) {
      if (oldWidget.play != widget.play) {
        if (widget.play) {
          _controller.play();
          _controller.setLooping(true);
        } else {
          _controller.pause();
        }
      }
      super.didUpdateWidget(oldWidget);
    }
  
    @override
    void dispose() {
      _controller.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return FutureBuilder(
        future: _initializeVideoPlayerFuture,
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            return VideoPlayer(_controller);
          } else {
            return Center(
              child: CircularProgressIndicator(),
            );
          }
        },
      );
    }
  }
  