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; return player.dispose;
}, []); }, []);
final aspectRatio = switch (info) { final controls = useCallback(
VideoInfo(:final width?, :final height?) when width > 0 && height > 0 => (VideoState _) =>
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: (_) =>
// Until media_kit moves to material_ui, this Material is needed. // Until media_kit moves to material_ui, this Material is needed.
Material( Material(
type: .transparency, type: .transparency,
child: Stack( child: ValueListenableBuilder(
valueListenable: loaded,
builder: (_, loaded, _) => Stack(
children: [ children: [
Positioned.fill( Positioned.fill(
child: GestureDetector( child: GestureDetector(
behavior: .opaque, behavior: .opaque,
onTap: loaded.value ? player.playOrPause : null, onTap: loaded ? player.playOrPause : null,
), ),
), ),
Positioned( Positioned(
@ -98,7 +87,7 @@ class const VideoPlayer(
padding: const .only(left: 4, right: 4, top: 16), padding: const .only(left: 4, right: 4, top: 16),
child: PlayerControls( child: PlayerControls(
player, player,
loading: !loaded.value, loading: !loaded,
size: info?.size, size: info?.size,
color: Colors.white, color: Colors.white,
actions: .new([ actions: .new([
@ -107,8 +96,7 @@ class const VideoPlayer(
final fullscreen = isFullscreen(context); final fullscreen = isFullscreen(context);
return IconButton( return IconButton(
onPressed: () => onPressed: () => toggleFullscreen(context),
toggleFullscreen(context),
color: Colors.white, color: Colors.white,
tooltip: fullscreen tooltip: fullscreen
? "Exit 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),
), ),
), ),
); );