From b536cc6ba4f09d13c87fca2fc4c8514820b8bd29 Mon Sep 17 00:00:00 2001 From: pyrossh Date: Sat, 26 Aug 2023 19:26:04 +0530 Subject: [PATCH] Fix iterator issue --- lib/providers/app_model.dart | 25 ++++++++++--------------- lib/widgets/verses_view.dart | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/providers/app_model.dart b/lib/providers/app_model.dart index 4e17b30e..4131dc80 100644 --- a/lib/providers/app_model.dart +++ b/lib/providers/app_model.dart @@ -209,12 +209,10 @@ class AppModel extends ChangeNotifier { ); } - clearEvents( - BuildContext context, - ) { - if (isPlaying) { - pause(); - } + clearEvents(BuildContext context) { + // if (isPlaying) { + // pause(); + // } clearSelections(); hideActions(context); } @@ -484,12 +482,7 @@ class AppModel extends ChangeNotifier { } bool isVerseSelected(Verse v) { - return selectedVerses.any((el) => el.index == v.index); - } - - bool isVerseHighlighted(BuildContext context) { - // box.read("${book}:${chapter}:${verse}", "color"); - return false; + return selectedVerses.any((el) => el.book == v.book && el.chapter == v.chapter && el.index == v.index); } void onVerseSelected(BuildContext context, Verse v) { @@ -522,13 +515,13 @@ class AppModel extends ChangeNotifier { } onPlay(BuildContext context) async { + final versesToPlay = List.from(selectedVerses); if (isPlaying) { pause(); } else { isPlaying = true; notifyListeners(); - // add locks todo - for (final v in selectedVerses) { + for (final v in versesToPlay) { final bibleName = bible.name; final book = (v.book + 1).toString().padLeft(2, "0"); final chapter = (v.chapter + 1).toString().padLeft(3, "0"); @@ -542,7 +535,9 @@ class AppModel extends ChangeNotifier { } catch (err) { log("Could not play audio", name: "play", error: (err.toString(), pathname)); FirebaseCrashlytics.instance.recordFlutterError(FlutterErrorDetails(exception: (err.toString(), pathname))); - showError(context, "Could not play audio"); + if (context.mounted) { + showError(context, "Could not play audio"); + } return; } finally { pause(); diff --git a/lib/widgets/verses_view.dart b/lib/widgets/verses_view.dart index 5cf8b91d..c719cd1f 100644 --- a/lib/widgets/verses_view.dart +++ b/lib/widgets/verses_view.dart @@ -80,7 +80,7 @@ class VersesView extends StatelessWidget { backgroundColor: app.darkMode ? Colors.grey.shade800 : Colors.grey.shade200, ) : TextStyle( - backgroundColor: app.getHighlight(v) ?? Theme.of(context).colorScheme.background, + backgroundColor: app.getHighlight(v) ?? context.theme.colorScheme.background, ), recognizer: TapGestureRecognizer() ..onTap = () {