feat: wire up app shell, log mood screen, and fix Android build
- Bootstrap ProviderScope in main.dart and move App to app.dart with light/dark theming - Add initial LogMoodScreen with mood entry flow and shared activity/mood widgets - Add kIsWeb guard in app_database.dart for drift web support - Enable Android core library desugaring required by flutter_local_notifications 21.x - Guard all async notifier state assignments with ref.mounted checks to prevent use-after-dispose errors when providers are auto-disposed mid-operation
This commit is contained in:
@@ -50,7 +50,7 @@ class ActivityNotifier extends Notifier<AsyncValue<void>> {
|
||||
required String colourHex,
|
||||
}) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
final next = await AsyncValue.guard(
|
||||
() => ref.read(activityDaoProvider).insertActivity(
|
||||
ActivitiesCompanion.insert(
|
||||
name: name,
|
||||
@@ -60,13 +60,17 @@ class ActivityNotifier extends Notifier<AsyncValue<void>> {
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!ref.mounted) return;
|
||||
state = next;
|
||||
}
|
||||
|
||||
Future<void> deleteActivity(int id) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
final next = await AsyncValue.guard(
|
||||
() => ref.read(activityDaoProvider).deleteActivity(id),
|
||||
);
|
||||
if (!ref.mounted) return;
|
||||
state = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ class InsightNotifier extends Notifier<AsyncValue<String?>> {
|
||||
final dao = ref.read(insightDaoProvider);
|
||||
|
||||
final cached = await dao.getCached(hash);
|
||||
if (!ref.mounted) return;
|
||||
if (cached != null) {
|
||||
state = AsyncData(cached.responseText);
|
||||
return;
|
||||
@@ -62,6 +63,7 @@ class InsightNotifier extends Notifier<AsyncValue<String?>> {
|
||||
rangeEnd: Value(rangeEnd),
|
||||
),
|
||||
);
|
||||
if (!ref.mounted) return;
|
||||
state = AsyncData(responseText);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,11 +33,12 @@ class LlmResponseNotifier extends Notifier<AsyncValue<String>> {
|
||||
|
||||
try {
|
||||
await for (final token in service.generateStream(prompt)) {
|
||||
if (_cancelled) break;
|
||||
if (_cancelled || !ref.mounted) break;
|
||||
buffer.write(token);
|
||||
state = AsyncData(buffer.toString());
|
||||
}
|
||||
} catch (e, st) {
|
||||
if (!ref.mounted) return;
|
||||
state = AsyncError(e, st);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class MoodEntryNotifier extends Notifier<AsyncValue<void>> {
|
||||
DateTime? timestamp,
|
||||
}) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
final next = await AsyncValue.guard(() async {
|
||||
final dao = ref.read(moodDaoProvider);
|
||||
await dao.insertEntryWithActivities(
|
||||
entry: MoodEntriesCompanion.insert(
|
||||
@@ -69,13 +69,17 @@ class MoodEntryNotifier extends Notifier<AsyncValue<void>> {
|
||||
tagIds: tagIds,
|
||||
);
|
||||
});
|
||||
if (!ref.mounted) return;
|
||||
state = next;
|
||||
}
|
||||
|
||||
Future<void> deleteEntry(int id) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
final next = await AsyncValue.guard(
|
||||
() => ref.read(moodDaoProvider).deleteEntry(id),
|
||||
);
|
||||
if (!ref.mounted) return;
|
||||
state = next;
|
||||
}
|
||||
|
||||
Future<void> updateEntry({
|
||||
@@ -85,7 +89,7 @@ class MoodEntryNotifier extends Notifier<AsyncValue<void>> {
|
||||
DateTime? timestamp,
|
||||
}) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
final next = await AsyncValue.guard(
|
||||
() => ref.read(moodDaoProvider).updateEntry(
|
||||
MoodEntriesCompanion(
|
||||
id: Value(id),
|
||||
@@ -95,6 +99,8 @@ class MoodEntryNotifier extends Notifier<AsyncValue<void>> {
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!ref.mounted) return;
|
||||
state = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class SettingsNotifier extends Notifier<AsyncValue<void>> {
|
||||
|
||||
Future<void> set(String key, String value) async {
|
||||
await ref.read(settingsDaoProvider).set(key, value);
|
||||
if (!ref.mounted) return;
|
||||
ref.invalidate(settingProvider(key));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user