fluttercommunity / fluttercommunity/chewie

Unhandled Exception: Bad state: Future already completed

Open
#549 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Dart
Stars
2.1k
Forks
1.1k
Avg merge
6d 8h
Merged PRs (30d)
6

Description

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 {
final Attachment attachment;

_VideoPlayerScreenState(this.attachment);

VideoPlayerController _controller;
ChewieController chewieController;
Future 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());
}
},
),
);
}
}`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the iOS failure from the supplied _VideoPlayerScreenState example, then read VideoPlayerController.initialize and ChewieController._initialize at the stack-trace locations. Compare the initialization flow with Android and determine whether it completes the same Future more than once. Done means the iOS example no longer reports “Future already completed” while video playback still initializes.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.