Skip to content

Commit

Permalink
Persist download managers through list updates (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elleo committed Nov 16, 2024
1 parent f2dbb9b commit bb41004
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/voice_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class _VoiceSelectorState extends State<VoiceSelector> {
List<String> languages = voices.keys.toList();
Map<dynamic, dynamic> selectedSubVoice = {};
int currentSubVoice = 0;
Map<String, DownloadManager> downloadManagers = {};

void findDownloads() async {
final Directory appDir = await getDataDir();
Expand Down Expand Up @@ -260,7 +261,12 @@ class _VoiceSelectorState extends State<VoiceSelector> {
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<dynamic, dynamic> subvoices = voices[selectedLanguage]
?.entries
.elementAt(index)
Expand Down Expand Up @@ -307,7 +313,7 @@ class _VoiceSelectorState extends State<VoiceSelector> {
? const Icon(Icons.stop)
: const Icon(Icons.play_arrow))),
const SizedBox(width: 32),
Text(voiceId!),
Text(voiceId),
subvoices.isEmpty
? const SizedBox()
: const Text(" - "),
Expand Down

0 comments on commit bb41004

Please # to comment.