chewie icon indicating copy to clipboard operation
chewie copied to clipboard

Unhandled Exception: Bad state: Future already completed

Open akmichael opened this issue 4 years ago • 1 comments

below code works in android. but doesnt work in iOs

 `+0200 Runner[326:18470] [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Bad state: Future already completed
 #0      _AsyncCompleter.complete (dart:async/future_impl.dart:45:31)
#1      VideoPlayerController.initialize (package:video_player/video_player.dart:310:25)

2 ChewieController._initialize (package:chewie/src/chewie_player.dart:395:7)`

     `
        'class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
                 final Attachment attachment;

                _VideoPlayerScreenState(this.attachment);

                VideoPlayerController _controller;
                ChewieController chewieController;
                Future<void> futureController;

               @override
               void initState() {
               _controller = Service().getAttachmentVideo(attachment.id);
     
                futureController = _controller.initialize();

             chewieController = ChewieController(
             videoPlayerController: _controller,
                 autoPlay: true,
                 looping: false,
                showControlsOnInitialize: false);
                super.initState();
          }

        @override
        void dispose() {
          // Ensure disposing of the VideoPlayerController to free up resources.
             chewieController.dispose();
           _controller.dispose();

           super.dispose();
           }

           @override
           Widget build(BuildContext context) {
          return Scaffold(
             body: FutureBuilder(
                  future: futureController,
                     builder: (context, snapshot) {
                       if (snapshot.connectionState == ConnectionState.done) {
       
	   // If the VideoPlayerController has finished initialization, use
        // the data it provides to limit the aspect ratio of the video.
        final Size size = _controller.value.size;
        return Chewie(
          controller: chewieController,
        );
      } else {
        // If the VideoPlayerController is still initializing, show a
        // loading spinner.
        return Center(child: CircularProgressIndicator());
       }
     },
     ),
  );
 }
}`

akmichael avatar Sep 25 '21 06:09 akmichael

Hi,

any clue on this please? I am struck.

anand

akmichael avatar Oct 13 '21 04:10 akmichael