fix use after dispose error from videos

Fixes #169
This commit is contained in:
Henry Hiles 2026-11-10 19:21:29 -05:00
commit 2d8cd4eff2
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -38,30 +38,19 @@ class const VideoPlayer(
return player.dispose;
}, []);
final aspectRatio = switch (info) {
VideoInfo(:final width?, :final height?) when width > 0 && height > 0 =>
width / height,
_ => 16 / 9,
};
return ConstrainedBox(
constraints: const .new(maxHeight: 300),
child: AspectRatio(
aspectRatio: aspectRatio,
child: ClipRRect(
borderRadius: .circular(12),
child: Video(
controller: controller,
controls: (_) =>
final controls = useCallback(
(VideoState _) =>
// Until media_kit moves to material_ui, this Material is needed.
Material(
type: .transparency,
child: Stack(
child: ValueListenableBuilder(
valueListenable: loaded,
builder: (_, loaded, _) => Stack(
children: [
Positioned.fill(
child: GestureDetector(
behavior: .opaque,
onTap: loaded.value ? player.playOrPause : null,
onTap: loaded ? player.playOrPause : null,
),
),
Positioned(
@ -98,7 +87,7 @@ class const VideoPlayer(
padding: const .only(left: 4, right: 4, top: 16),
child: PlayerControls(
player,
loading: !loaded.value,
loading: !loaded,
size: info?.size,
color: Colors.white,
actions: .new([
@ -107,8 +96,7 @@ class const VideoPlayer(
final fullscreen = isFullscreen(context);
return IconButton(
onPressed: () =>
toggleFullscreen(context),
onPressed: () => toggleFullscreen(context),
color: Colors.white,
tooltip: fullscreen
? "Exit fullscreen"
@ -130,6 +118,22 @@ class const VideoPlayer(
),
),
),
[uri, encrypted, filename, info],
);
final aspectRatio = switch (info) {
VideoInfo(:final width?, :final height?) when width > 0 && height > 0 =>
width / height,
_ => 16 / 9,
};
return ConstrainedBox(
constraints: const .new(maxHeight: 300),
child: AspectRatio(
aspectRatio: aspectRatio,
child: ClipRRect(
borderRadius: .circular(12),
child: Video(controller: controller, controls: controls),
),
),
);