I’m using ChewieController for video player. For me, when an error is shown, setState
is triggered to re-initialize _chewieController
, but when setState
is called, the controller blinks (progress bar video). I need to get rid of blinking controls when setState is triggered, how can I do this?
_chewieController = ChewieController(
videoPlayerController: videoPlayerController,
autoInitialize: true,
allowFullScreen: true,
aspectRatio: widget.videoContent.isVertical ? 0.5 : 16 / 9,
looping: false,
autoPlay: true,
showControlsOnInitialize: false,
errorBuilder: (context, errorMessage) {
if (errorMessage == "Failed to load video: Operation Stopped" ||
errorMessage == "Failed to load video: unknown error" &&
numberTryInit <= maxNumberTryInit) {
WidgetsBinding.instance.addPostFrameCallback((_) => setState(() {}));
numberTryInit = numberTryInit + 1;
return const SizedBox.shrink();
}
return Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: CustomText.title(
text: "error_load_video".tr(),
textAlign: TextAlign.center,
),
),
);
},
showOptions: false,
cupertinoProgressColors: ChewieProgressColors(
handleColor: Colors.white,
playedColor: AppProperties.accentColor,
bufferedColor: const Color.fromRGBO(200, 200, 200, 0.8),
),
materialProgressColors: ChewieProgressColors(
handleColor: Colors.white,
playedColor: AppProperties.accentColor,
bufferedColor: const Color.fromRGBO(200, 200, 200, 0.8),
),
placeholder: const Center(child: CircularProgressIndicator()),
);
return SafeArea(
child: FutureBuilder<bool>(
future: _initVideoController(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Stack(children: [
Chewie(
controller: _chewieController,
),
if (snapshot.data != null && !snapshot.data!)
Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: CustomText.title(
text: "error_load_video".tr(),
textAlign: TextAlign.center,
),
),
)
]);
}