Skip to content

Commit 702b0d1

Browse files
committed
sharedprefs to hive
1 parent 9089179 commit 702b0d1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/dashbot/providers/dashbot_providers.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:convert';
2+
import 'package:apidash/services/services.dart';
23
import 'package:flutter_riverpod/flutter_riverpod.dart';
3-
44
import '../services/services.dart';
55

66
final chatMessagesProvider =
@@ -17,19 +17,16 @@ class ChatMessagesNotifier extends StateNotifier<List<Map<String, dynamic>>> {
1717
_loadMessages();
1818
}
1919

20-
static const _storageKey = 'chatMessages';
21-
2220
Future<void> _loadMessages() async {
23-
final prefs = await SharedPreferences.getInstance();
24-
final messages = prefs.getString(_storageKey);
21+
final messages = await hiveHandler.getDashbotMessages();
2522
if (messages != null) {
2623
state = List<Map<String, dynamic>>.from(json.decode(messages));
2724
}
2825
}
2926

3027
Future<void> _saveMessages() async {
31-
final prefs = await SharedPreferences.getInstance();
32-
await prefs.setString(_storageKey, json.encode(state));
28+
final messages = json.encode(state);
29+
await hiveHandler.saveDashbotMessages(messages);
3330
}
3431

3532
void addMessage(Map<String, dynamic> message) {

lib/services/hive_services.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,16 @@ class HiveHandler {
147147
Future<dynamic> getHistoryRequest(String id) async =>
148148
await historyLazyBox.get(id);
149149
Future<void> setHistoryRequest(
150-
String id, Map<String, dynamic>? historyRequestJsoon) =>
151-
historyLazyBox.put(id, historyRequestJsoon);
150+
String id, Map<String, dynamic>? historyRequestJson) =>
151+
historyLazyBox.put(id, historyRequestJson);
152152

153153
Future<void> deleteHistoryRequest(String id) => historyLazyBox.delete(id);
154154

155+
Future<dynamic> getDashbotMessages() async =>
156+
await dashBotBox.get(kKeyDashBotBoxIds);
157+
Future<void> saveDashbotMessages(String messages) =>
158+
dashBotBox.put(kKeyDashBotBoxIds, messages);
159+
155160
Future clearAllHistory() async {
156161
await historyMetaBox.clear();
157162
await historyLazyBox.clear();

0 commit comments

Comments
 (0)