- 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
104 lines
2.6 KiB
Dart
104 lines
2.6 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:drift/drift.dart';
|
|
import 'package:drift_flutter/drift_flutter.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
import 'tables.dart';
|
|
import 'daos/mood_dao.dart';
|
|
import 'daos/activity_dao.dart';
|
|
import 'daos/insight_dao.dart';
|
|
import 'daos/settings_dao.dart';
|
|
|
|
part 'app_database.g.dart';
|
|
|
|
@DriftDatabase(
|
|
tables: [
|
|
MoodEntries,
|
|
Activities,
|
|
EntryActivities,
|
|
Tags,
|
|
EntryTags,
|
|
LlmInsights,
|
|
UserSettings,
|
|
],
|
|
daos: [
|
|
MoodDao,
|
|
ActivityDao,
|
|
InsightDao,
|
|
SettingsDao,
|
|
],
|
|
)
|
|
class AppDatabase extends _$AppDatabase {
|
|
AppDatabase() : super(_openConnection());
|
|
|
|
@override
|
|
int get schemaVersion => 1;
|
|
|
|
@override
|
|
MigrationStrategy get migration => MigrationStrategy(
|
|
onCreate: (m) async {
|
|
await m.createAll();
|
|
await _seedDefaultActivities();
|
|
},
|
|
onUpgrade: (m, from, to) async {
|
|
// Future migrations go here
|
|
},
|
|
);
|
|
|
|
Future<void> _seedDefaultActivities() async {
|
|
final defaults = [
|
|
(
|
|
name: 'Exercise',
|
|
icon: 0xe567,
|
|
colour: '#FF6B6B'
|
|
), // Icons.fitness_center
|
|
(name: 'Good sleep', icon: 0xe7f5, colour: '#7B68EE'), // Icons.bedtime
|
|
(name: 'Social', icon: 0xe7ef, colour: '#FFB347'), // Icons.people
|
|
(name: 'Work', icon: 0xe8b6, colour: '#4FC3F7'), // Icons.work
|
|
(name: 'Food', icon: 0xe56c, colour: '#81C784'), // Icons.restaurant
|
|
(name: 'Reading', icon: 0xe865, colour: '#F06292'), // Icons.menu_book
|
|
(name: 'Outdoors', icon: 0xe1a1, colour: '#AED581'), // Icons.park
|
|
(
|
|
name: 'Family',
|
|
icon: 0xe8a1,
|
|
colour: '#FFD54F'
|
|
), // Icons.family_restroom
|
|
(
|
|
name: 'Meditation',
|
|
icon: 0xe7fb,
|
|
colour: '#80CBC4'
|
|
), // Icons.self_improvement
|
|
(name: 'Travel', icon: 0xe8b5, colour: '#FF8A65'), // Icons.flight
|
|
];
|
|
|
|
for (final (index, a) in defaults.indexed) {
|
|
await into(activities).insert(
|
|
ActivitiesCompanion.insert(
|
|
name: a.name,
|
|
iconCodepoint: a.icon,
|
|
colourHex: a.colour,
|
|
sortOrder: Value(index),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
QueryExecutor _openConnection() {
|
|
if (kIsWeb) {
|
|
return driftDatabase(
|
|
name: 'lumina_db',
|
|
web: DriftWebOptions(
|
|
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
|
|
driftWorker: Uri.parse('drift_worker.dart.js'),
|
|
),
|
|
);
|
|
}
|
|
return driftDatabase(
|
|
name: 'lumina_db',
|
|
native: DriftNativeOptions(
|
|
databaseDirectory: getApplicationSupportDirectory,
|
|
),
|
|
);
|
|
}
|