From bb41004ec4553c2ec2b5beb90ae3763c8295bf87 Mon Sep 17 00:00:00 2001 From: Mike Sheldon Date: Sat, 16 Nov 2024 22:32:08 +0000 Subject: [PATCH] Persist download managers through list updates (fixes #15) --- lib/voice_selector.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/voice_selector.dart b/lib/voice_selector.dart index 422109d..fef40f5 100644 --- a/lib/voice_selector.dart +++ b/lib/voice_selector.dart @@ -36,6 +36,7 @@ class _VoiceSelectorState extends State { List languages = voices.keys.toList(); Map selectedSubVoice = {}; int currentSubVoice = 0; + Map downloadManagers = {}; void findDownloads() async { final Directory appDir = await getDataDir(); @@ -260,7 +261,12 @@ class _VoiceSelectorState extends State { itemBuilder: (BuildContext context, int index) { String? voiceId = voices[selectedLanguage]?.keys.elementAt(index); - DownloadManager downloadManager = DownloadManager(); + if (voiceId == null) { + return const SizedBox(); + } + DownloadManager downloadManager = + downloadManagers[voiceId] ?? DownloadManager(); + downloadManagers[voiceId] = downloadManager; Map subvoices = voices[selectedLanguage] ?.entries .elementAt(index) @@ -307,7 +313,7 @@ class _VoiceSelectorState extends State { ? const Icon(Icons.stop) : const Icon(Icons.play_arrow))), const SizedBox(width: 32), - Text(voiceId!), + Text(voiceId), subvoices.isEmpty ? const SizedBox() : const Text(" - "),