From 0ccebb221780ec47c1d2648f28ed66c88a1c6f99 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Wed, 13 May 2020 22:05:18 +0200 Subject: [PATCH] mobile: Fix handling of works without sections --- mobile/lib/playback.dart | 6 ++++-- mobile/lib/screens/program.dart | 3 ++- mobile/lib/widgets/player_bar.dart | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mobile/lib/playback.dart b/mobile/lib/playback.dart index d169b6a..f257eea 100644 --- a/mobile/lib/playback.dart +++ b/mobile/lib/playback.dart @@ -341,8 +341,10 @@ class _PlaybackService extends BackgroundAudioTask { if (partIds.isNotEmpty) { subtitleBuffer.write(': '); - final section = - workInfo.sections.lastWhere((s) => s.beforePartIndex <= partIds[0]); + final section = workInfo.sections.lastWhere( + (s) => s.beforePartIndex <= partIds[0], + orElse: () => null, + ); if (section != null) { subtitleBuffer.write(section.title); diff --git a/mobile/lib/screens/program.dart b/mobile/lib/screens/program.dart index fe6bad4..9a3d170 100644 --- a/mobile/lib/screens/program.dart +++ b/mobile/lib/screens/program.dart @@ -100,6 +100,7 @@ class _ProgramScreenState extends State { if (recordingInfo.recording.work != lastWorkId) { lastWorkId = recordingInfo.recording.work; workInfo = await backend.db.getWork(lastWorkId); + lastSectionIndex = null; } children.addAll([ @@ -118,7 +119,7 @@ class _ProgramScreenState extends State { final sectionIndex = workInfo.sections .lastIndexWhere((s) => s.beforePartIndex <= partId); - if (sectionIndex != lastSectionIndex) { + if (sectionIndex != lastSectionIndex && sectionIndex >= 0) { lastSectionIndex = sectionIndex; children.add(Padding( padding: const EdgeInsets.only( diff --git a/mobile/lib/widgets/player_bar.dart b/mobile/lib/widgets/player_bar.dart index 76694d7..055c9fc 100644 --- a/mobile/lib/widgets/player_bar.dart +++ b/mobile/lib/widgets/player_bar.dart @@ -62,9 +62,11 @@ class _PlayerBarState extends State { if (_partIds.isNotEmpty) { subtitleBuffer.write(': '); - final section = _workInfo.sections - .lastWhere((s) => s.beforePartIndex <= _partIds[0]); - + final section = _workInfo.sections.lastWhere( + (s) => s.beforePartIndex <= _partIds[0], + orElse: () => null, + ); + if (section != null) { subtitleBuffer.write(section.title); subtitleBuffer.write(': ');