我用Flutter开发了演示web应用程序并将其上传到我的服务器上,我使用Hive 数据库在 web 应用程序上存储了一些数据。
最近我发现当我打开 web 应用程序并在上面存储一些数据时,如果我再次使用不同的浏览器我看不到以前存储的数据,似乎 Flutter web 上的 Hive 会将数据存储在客户端缓存的某个位置。
我现在有3个问题:
hive 数据库的位置在哪里,如何手动访问它?
如何解决此问题并使用 Flutter Web 将数据存储在我的服务器上,以便每个用户都可以看到相同的数据?
我应该在服务器端使用 Dart 来实现这个目标吗?如果是,我可以从哪里开始并找到好的文件?
这是我保存和加载数据的代码:
void _initHiveDB() async {
if (_isDBInited) {
return;
}
if(!kIsWeb){
final documentsDirectory = await Path_Provider.getApplicationDocumentsDirectory();
Hive.init(documentsDirectory.path);
}
Hive.registerAdapter(ComplaintModelAdapter(), 0);
_isDBInited = true;
}
Future<bool> saveNewComplaint(ComplaintModel complaintModel)async{
try{
if(_complaintBox==null||!_complaintBox.isOpen){
_complaintBox = await Hive.openBox('Complaints');
}
else{
_complaintBox = Hive.box('Complaints');
}
_complaintBox.add(complaintModel);
return true;
}
catch(exc){
return false;
}
}
Future<List<ComplaintModel>> loadAllComplaints() async {
try{
if(_complaintBox==null||!_complaintBox.isOpen){
_complaintBox = await Hive.openBox('Complaints');
}
else{
_complaintBox = Hive.box('Complaints');
}
//Box<ComplaintModel> complaintBox = await Hive.openBox('Complaints');
//Box<ComplaintModel> complaintBox = await Hive.box('Complaints');
List<ComplaintModel> complaints = _complaintBox.values.toList();
return complaints;
}
catch(exc){
return null;
}}