11import 'dart:developer' ;
2+
23import 'package:flutter/foundation.dart' ;
4+ import 'package:flutter_alarm_manager_poc/hive/models/alarm_action.dart' ;
35import 'package:hive_flutter/hive_flutter.dart' ;
4- import '../models/alarm_action.dart' ;
56
67class DatabaseService {
8+ // Private constructor
9+ DatabaseService ._();
10+
711 static const String alarmBoxName = 'alarm_actions' ;
812 static DatabaseService ? _instance;
913 late Box <AlarmAction > _alarmBox;
1014
11- // Private constructor
12- DatabaseService ._();
13-
1415 // Singleton instance getter
1516 static DatabaseService get instance {
1617 _instance ?? = DatabaseService ._();
@@ -27,7 +28,7 @@ class DatabaseService {
2728 Hive .registerAdapter (AlarmActionAdapter ());
2829 _alarmBox = await Hive .openBox <AlarmAction >(alarmBoxName);
2930 log ('Hive initialized and box opened successfully.' );
30- } catch (e) {
31+ } on Exception catch (e) {
3132 log ('Failed to initialize Hive or open box: $e ' );
3233 }
3334 }
@@ -40,20 +41,20 @@ class DatabaseService {
4041 );
4142 log ('Stored alarm action: $actionType ' );
4243
43- var actions = getAllAlarmActions ();
44+ final actions = getAllAlarmActions ();
4445 log ('Retrieved ${actions .length } alarm actions.' );
45- } catch (e) {
46+ } on Exception catch (e) {
4647 log ('Failed to store alarm action: $e ' );
4748 }
4849 }
4950
5051 // Retrieve all alarm actions from the Hive box
5152 List <AlarmAction > getAllAlarmActions () {
5253 try {
53- var actions = _alarmBox.values;
54+ final actions = _alarmBox.values;
5455 log ('Retrieved ${actions .length } alarm actions.' );
5556 return actions.toList ();
56- } catch (e) {
57+ } on Exception catch (e) {
5758 log ('Failed to retrieve alarm actions: $e ' );
5859 return [];
5960 }
@@ -64,7 +65,7 @@ class DatabaseService {
6465 try {
6566 await _alarmBox.clear ();
6667 log ('All alarm actions cleared.' );
67- } catch (e) {
68+ } on Exception catch (e) {
6869 log ('Failed to clear alarm actions: $e ' );
6970 }
7071 }
0 commit comments