feat: migrate shared_preferences to hive (#343)

This commit is contained in:
Levi authored and GitHub committed 2024-01-24 15:49:51 +08:00
1 parent f2cd686563
commit b89c7bc608
15 files changed
+247 -143

No files matched your search

@@ -1,26 +0,0 @@
import 'package:shared_preferences/shared_preferences.dart';
class HistoryController {
// Get History in List<String>
Future<List<String>> getAllHistory() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
List<String>? historyList = preferences.getStringList('history');
if(historyList == null) {
return [];
}
return historyList;
}
// Get Existing History & Add New History
void addHistory(String historyText) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
List<String> existingHistoryData = await getAllHistory();
existingHistoryData.add(historyText);
preferences.setStringList('history', existingHistoryData);
}
void clearHistory() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.remove('history');
}
}
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:gopeed/app/modules/history/controller/history_controller.dart';
import 'package:gopeed/database/database.dart';
class HistoryView extends StatefulWidget {
const HistoryView({
@@ -62,8 +62,7 @@ class _HistoryViewState extends State<HistoryView> {
children: <Widget>[
IconButton(
onPressed: () {
HistoryController _controller = HistoryController();
_controller.clearHistory();
Database.instance.clearCreateHistory();
Navigator.pop(context);
},
tooltip: "clearHistory".tr,