Files
1356/lifetimer/lib/data/services/offline_cache_service.dart
T
Tomas Dvorak 37ffb93923 feat: Complete Phase 1 - Full Flutter app implementation with comprehensive features
Version: 1.1.0

Major changes:
- Implemented complete Flutter app structure with all core features
- Added comprehensive UI screens for auth, countdown, goals, profile, settings, and social features
- Integrated Supabase backend with authentication and data repositories
- Added offline support with Hive caching and local storage
- Implemented comprehensive routing with go_router
- Added location services with Google Maps integration
- Implemented notifications and home widget support
- Added voice recording capabilities and AI chat features
- Created comprehensive test suite and documentation
- Added Android and iOS platform configurations
- Implemented achievements system and social features
- Added calendar integration and bucket list functionality

This represents a complete Phase 1 milestone with 3,775 additions across 31 files.
2026-01-04 14:33:54 +01:00

94 lines
2.5 KiB
Dart

import 'package:hive_flutter/hive_flutter.dart';
import '../models/cached_goal_model.dart';
class OfflineCacheService {
static const String _goalsBoxName = 'cached_goals';
static const String _userBoxName = 'cached_user';
static const String _countdownBoxName = 'cached_countdown';
late Box<CachedGoal> _goalsBox;
late Box _userBox;
late Box _countdownBox;
Future<void> init() async {
await Hive.initFlutter();
if (!Hive.isAdapterRegistered(0)) {
Hive.registerAdapter(CachedGoalAdapter());
}
_goalsBox = await Hive.openBox<CachedGoal>(_goalsBoxName);
_userBox = await Hive.openBox(_userBoxName);
_countdownBox = await Hive.openBox(_countdownBoxName);
}
Future<void> cacheGoals(List<CachedGoal> goals) async {
await _goalsBox.clear();
for (var goal in goals) {
await _goalsBox.put(goal.id, goal);
}
}
Future<List<CachedGoal>> getCachedGoals() async {
return _goalsBox.values.toList();
}
Future<CachedGoal?> getCachedGoal(String goalId) async {
return _goalsBox.get(goalId);
}
Future<void> cacheGoal(CachedGoal goal) async {
await _goalsBox.put(goal.id, goal);
}
Future<void> deleteCachedGoal(String goalId) async {
await _goalsBox.delete(goalId);
}
Future<void> markGoalAsDirty(String goalId) async {
final goal = _goalsBox.get(goalId);
if (goal != null) {
await _goalsBox.put(goalId, goal.copyWith(isDirty: true));
}
}
Future<List<CachedGoal>> getDirtyGoals() async {
return _goalsBox.values.where((goal) => goal.isDirty).toList();
}
Future<void> clearDirtyFlag(String goalId) async {
final goal = _goalsBox.get(goalId);
if (goal != null) {
await _goalsBox.put(goalId, goal.copyWith(isDirty: false));
}
}
Future<void> cacheUserData(Map<String, dynamic> userData) async {
await _userBox.putAll(userData);
}
Future<Map<String, dynamic>> getCachedUserData() async {
return Map<String, dynamic>.from(_userBox.toMap());
}
Future<void> cacheCountdownData(Map<String, dynamic> countdownData) async {
await _countdownBox.putAll(countdownData);
}
Future<Map<String, dynamic>> getCachedCountdownData() async {
return Map<String, dynamic>.from(_countdownBox.toMap());
}
Future<void> clearAllCache() async {
await _goalsBox.clear();
await _userBox.clear();
await _countdownBox.clear();
}
Future<void> close() async {
await _goalsBox.close();
await _userBox.close();
await _countdownBox.close();
}
}