问题描述
我在 main.dart 文件中初始化并打开 Hive 数据库框并执行 crud 操作。当我重新加载应用程序时应用程序冻结,但当我删除 Hive.openBox() 后面的“await”关键字时解冻; await Hive.openBox(ExpenseBoxName); 但应用将停止执行数据库操作。
第三个片段是我执行 crud 操作的地方
解决方法
像这样初始化数据库
void main() async
{
WidgetsFlutterBinding.ensureInitialized();
final document = await getApplicationDocumentsDirectory();
Hive.init(document.path);
await Hive.openBox<String>(datbase_name");
runApp(MyApp());
}