fixing some null pointers

This commit is contained in:
otsmr 2025-10-29 00:19:16 +01:00
parent 0bacbe6671
commit 37790aa304

View file

@ -189,6 +189,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
Future<void> handleNextDownloadedMedia( Future<void> handleNextDownloadedMedia(
bool showTwonly, bool showTwonly,
) async { ) async {
if (allMediaFiles.isEmpty) return;
currentMessage = allMediaFiles.removeAt(0); currentMessage = allMediaFiles.removeAt(0);
final currentMediaLocal = final currentMediaLocal =
await MediaFileService.fromMediaId(currentMessage!.mediaId!); await MediaFileService.fromMediaId(currentMessage!.mediaId!);
@ -224,7 +225,8 @@ class _MediaViewerViewState extends State<MediaViewerView> {
currentMediaLocal.mediaFile.displayLimitInMilliseconds == null, currentMediaLocal.mediaFile.displayLimitInMilliseconds == null,
); );
await videoController?.initialize().then((_) { await videoController?.initialize().then((_) {
videoController!.play(); if (videoController == null) return;
videoController?.play();
videoController?.addListener(() { videoController?.addListener(() {
setState(() { setState(() {
progress = 1 - progress = 1 -
@ -259,20 +261,20 @@ class _MediaViewerViewState extends State<MediaViewerView> {
void startTimer() { void startTimer() {
nextMediaTimer?.cancel(); nextMediaTimer?.cancel();
progressTimer?.cancel(); progressTimer?.cancel();
nextMediaTimer = Timer(canBeSeenUntil!.difference(DateTime.now()), () { if (canBeSeenUntil != null) {
if (context.mounted) { nextMediaTimer = Timer(canBeSeenUntil!.difference(DateTime.now()), () {
nextMediaOrExit(); if (context.mounted) {
} nextMediaOrExit();
}); }
progressTimer = Timer.periodic(const Duration(milliseconds: 10), (timer) { });
if (canBeSeenUntil != null) { progressTimer = Timer.periodic(const Duration(milliseconds: 10), (timer) {
final difference = canBeSeenUntil!.difference(DateTime.now()); final difference = canBeSeenUntil!.difference(DateTime.now());
// Calculate the progress as a value between 0.0 and 1.0 // Calculate the progress as a value between 0.0 and 1.0
progress = difference.inMilliseconds / progress = difference.inMilliseconds /
(currentMedia!.mediaFile.displayLimitInMilliseconds!); (currentMedia!.mediaFile.displayLimitInMilliseconds!);
setState(() {}); setState(() {});
} });
}); }
} }
Future<void> onPressedSaveToGallery() async { Future<void> onPressedSaveToGallery() async {
@ -464,7 +466,8 @@ class _MediaViewerViewState extends State<MediaViewerView> {
Positioned.fill( Positioned.fill(
child: VideoPlayer(videoController!), child: VideoPlayer(videoController!),
), ),
if (currentMedia!.mediaFile.type == MediaType.image) if (currentMedia != null &&
currentMedia!.mediaFile.type == MediaType.image)
Positioned.fill( Positioned.fill(
child: Image.file( child: Image.file(
currentMedia!.tempPath, currentMedia!.tempPath,