Skip to content

Commit 970538e

Browse files
committed
Fix setState on unmounted components
1 parent 2e04c6a commit 970538e

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

packages/flyer_chat_video_message/lib/src/flyer_chat_video_message.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,22 @@ class _FlyerChatVideoMessageState extends State<FlyerChatVideoMessage> {
147147
quality: 25,
148148
headers: widget.headers,
149149
);
150-
setState(() {
151-
// TODO should we add 'image' package to decode and get height and width
152-
// to update _aspectRatio?
150+
if (mounted) {
151+
setState(() {
152+
// TODO should we add 'image' package to decode and get height and width
153+
// to update _aspectRatio?
153154

154-
// import 'package:image/image.dart' as img;
155+
// import 'package:image/image.dart' as img;
155156

156-
// final decoded = img.decodeImage(coverImageBytes!);
157-
// if (decoded != null) {
158-
// final width = decoded.width;
159-
// final height = decoded.height;
160-
// }
157+
// final decoded = img.decodeImage(coverImageBytes!);
158+
// if (decoded != null) {
159+
// final width = decoded.width;
160+
// final height = decoded.height;
161+
// }
161162

162-
_placeholderProvider = MemoryImage(coverImageBytes!);
163-
});
163+
_placeholderProvider = MemoryImage(coverImageBytes!);
164+
});
165+
}
164166
}
165167

166168
@override

packages/flyer_chat_video_message/lib/src/widgets/full_screen_video_player.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ class _FullscreenVideoPlayerState extends State<FullscreenVideoPlayer> {
4646
}
4747

4848
await _videoPlayer.initialize();
49-
setState(() {
50-
_aspectRatio = _videoPlayer.value.aspectRatio;
51-
_chewieController = ChewieController(
52-
videoPlayerController: _videoPlayer,
53-
autoPlay: true,
54-
allowFullScreen: false,
55-
autoInitialize: false,
56-
);
57-
});
49+
if (mounted) {
50+
setState(() {
51+
_aspectRatio = _videoPlayer.value.aspectRatio;
52+
_chewieController = ChewieController(
53+
videoPlayerController: _videoPlayer,
54+
autoPlay: true,
55+
allowFullScreen: false,
56+
autoInitialize: false,
57+
);
58+
});
59+
}
5860
}
5961

6062
@override

0 commit comments

Comments
 (0)