@tduncan / Cortana / commits / 896ab91

fix(models): guard modelSearchQueryProvider and sort notifier against disposed Ref #88

abdulmominsakib committed Sep 21, 2026 at 09:35 UTC 896ab9145657c0db707a727785b09da7fffccd72
2 files changed +17 -5
lib/features/models/providers/model_picker_providers.dart
+13 -3
@@ -8,8 +8,15 @@ class ModelSearchNotifier extends Notifier<String> {
8 @override
9 String build() => '';
10
11 - void setQuery(String q) => state = q;
12 - void clear() => state = '';
11 + void setQuery(String q) {
12 + if (!ref.mounted) return;
13 + state = q;
14 + }
15 +
16 + void clear() {
17 + if (!ref.mounted) return;
18 + state = '';
19 + }
20 }
21
22 enum ModelSortOption { favorites, nameAsc, sizeAsc, sizeDesc, contextDesc }
@@ -21,5 +28,8 @@ class ModelSortNotifier extends Notifier<ModelSortOption> {
28 @override
29 ModelSortOption build() => ModelSortOption.favorites;
30
24 - void setOption(ModelSortOption option) => state = option;
31 + void setOption(ModelSortOption option) {
32 + if (!ref.mounted) return;
33 + state = option;
34 + }
35 }
lib/features/models/views/model_picker_sheet.dart
+4 -2
@@ -35,8 +35,10 @@ class _ModelPickerSheetState extends ConsumerState<ModelPickerSheet> {
35 void deactivate() {
36 // Reset search when the sheet closes so the next open starts from a
37 // clean, matching state instead of an empty box that's still filtering.
38 - final searchNotifier = ref.read(modelSearchQueryProvider.notifier);
39 - Future.microtask(() => searchNotifier.clear());
38 + try {
39 + final searchNotifier = ref.read(modelSearchQueryProvider.notifier);
40 + Future.microtask(() => searchNotifier.clear());
41 + } catch (_) {}
42 super.deactivate();
43 }
44