import "dart:convert"; import "package:flutter/foundation.dart"; import "package:hive_flutter/hive_flutter.dart"; import "../models/brr_state.dart"; class StorageService { static const _boxName = "brr_box"; static const _stateKey = "brr_state"; Future> _openBox() => Hive.openBox(_boxName); Future saveState(BRRState state) async { final box = await _openBox(); await box.put(_stateKey, jsonEncode(state.toJson())); } Future loadState() async { final box = await _openBox(); final jsonString = box.get(_stateKey); if (jsonString == null) return null; try { return BRRState.fromJson(jsonDecode(jsonString) as Map); } catch (e, stackTrace) { debugPrint("[StorageService] loadState failed: $e"); debugPrintStack(stackTrace: stackTrace); return null; } } Future clearState() async { final box = await _openBox(); await box.delete(_stateKey); } }