![](/img/trans.png)
[英]Flutter - get_it error : Invalid argument (Object of type AppModel is not registered inside GetIt
[英]Hive adapters and boxes with Get_it how should i regester them into getit
我總是遇到 hive boxies 實例和未初始化盒子或適配器的錯誤,所以我決定在一個地方注冊它們並在所有地方使用它。但我不知道如何使用和注冊適配器和盒子
我沒有嘗試過,因為我不知道如何實現
使用Hive.registerAdapter()
注冊適配器的推薦位置是在Hive.initFlutter()
完成后立即使用,然后使用您制作適配器的 object 類型打開您的盒子,如下所示:
Future<void> main() async {
await Hive.initFlutter();
Hive.registerAdapter<Question>(QuestionAdapter());
await Hive.openBox<Question>("questions");
runApp(MyApp());
}
現在“問題”框將可以通過以下方式直接在整個應用程序中使用:
Hive.box("questions");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.