Implement initial features for husband's companion app, including mock data service and husband notes screen. Refactor scripture and cycle services for improved stability and testability. Address iOS Safari web app startup issue by removing deprecated initialization. - Implemented MockDataService and HusbandNotesScreen. - Converted _DashboardTab and DevotionalScreen to StatefulWidgets for robust scripture provider initialization. - Refactored CycleService to use immutable CycleInfo class, reducing UI rebuilds. - Removed deprecated window.flutterConfiguration from index.html, resolving Flutter web app startup failure on iOS Safari. - Updated and fixed related tests.
82 lines
2.3 KiB
Dart
82 lines
2.3 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
import '../models/user_profile.dart';
|
|
import '../models/cycle_entry.dart';
|
|
import '../services/cycle_service.dart';
|
|
|
|
/// Provider for the user profile
|
|
final userProfileProvider = StateNotifierProvider<UserProfileNotifier, UserProfile?>((ref) {
|
|
return UserProfileNotifier();
|
|
});
|
|
|
|
/// Notifier for the user profile
|
|
class UserProfileNotifier extends StateNotifier<UserProfile?> {
|
|
UserProfileNotifier() : super(null) {
|
|
_loadProfile();
|
|
}
|
|
|
|
void _loadProfile() {
|
|
final box = Hive.box<UserProfile>('user_profile');
|
|
state = box.get('current_user');
|
|
}
|
|
|
|
Future<void> updateProfile(UserProfile profile) async {
|
|
final box = Hive.box<UserProfile>('user_profile');
|
|
await box.put('current_user', profile);
|
|
state = profile;
|
|
}
|
|
|
|
Future<void> clearProfile() async {
|
|
final box = Hive.box<UserProfile>('user_profile');
|
|
await box.clear();
|
|
state = null;
|
|
}
|
|
}
|
|
|
|
/// Provider for cycle entries
|
|
final cycleEntriesProvider = StateNotifierProvider<CycleEntriesNotifier, List<CycleEntry>>((ref) {
|
|
return CycleEntriesNotifier();
|
|
});
|
|
|
|
/// Notifier for cycle entries
|
|
class CycleEntriesNotifier extends StateNotifier<List<CycleEntry>> {
|
|
CycleEntriesNotifier() : super([]) {
|
|
_loadEntries();
|
|
}
|
|
|
|
void _loadEntries() {
|
|
final box = Hive.box<CycleEntry>('cycle_entries');
|
|
state = box.values.toList()..sort((a, b) => b.date.compareTo(a.date));
|
|
}
|
|
|
|
Future<void> addEntry(CycleEntry entry) async {
|
|
final box = Hive.box<CycleEntry>('cycle_entries');
|
|
await box.put(entry.id, entry);
|
|
_loadEntries();
|
|
}
|
|
|
|
Future<void> updateEntry(CycleEntry entry) async {
|
|
final box = Hive.box<CycleEntry>('cycle_entries');
|
|
await box.put(entry.id, entry);
|
|
_loadEntries();
|
|
}
|
|
|
|
Future<void> deleteEntry(String id) async {
|
|
final box = Hive.box<CycleEntry>('cycle_entries');
|
|
await box.delete(id);
|
|
_loadEntries();
|
|
}
|
|
|
|
Future<void> clearEntries() async {
|
|
final box = Hive.box<CycleEntry>('cycle_entries');
|
|
await box.clear();
|
|
state = [];
|
|
}
|
|
}
|
|
|
|
/// Computed provider for current cycle info
|
|
final currentCycleInfoProvider = Provider((ref) {
|
|
final user = ref.watch(userProfileProvider);
|
|
return CycleService.calculateCycleInfo(user);
|
|
});
|