我有一个类,在这里我正在执行graphql设置和蜂窝框设置。这是一堂课-
class GraphQLConfiguration {
ValueNotifier<GraphQLClient> client = new ValueNotifier<GraphQLClient>(
GraphQLClient(
cache:
GraphQLCache(store: HiveStore(Hive.box(HiveStore.defaultBoxName))),
link: HttpLink('http://localhost:4000/graphql/',),
),
);
GraphQLConfiguration() {
initializeHive();
}
void initializeHive() async {
await initHiveForFlutter(); // or await initHiveForFlutter();
await Hive.openBox('bolBox');
}
}现在我在颤振主方法中初始化这个类-
Future main() async {
GraphQLConfiguration graphql = new GraphQLConfiguration();
}当我运行这段代码时,我会收到一条错误消息-
错误-未处理异常: HiveError:框未找到。你忘了给Hive.openBox()打电话了吗?
我也跟着这个帖子,找不到盒子。你忘记打电话给Hive.openBox()了吗?,没帮上忙。
发布于 2021-06-18 06:03:38
通过使用提供程序给Hive一个主目录来初始化它
final Directory appDocDir = await getApplicationDocumentsDirectory();
Hive.init(appDocDir.path);然后打开盒子
await Hive.openBox('bolBox');发布于 2021-10-04 03:48:25
在根文件夹中添加initHiveForFlutter &它解决了问题。
void main() async{
await initHiveForFlutter();
runApp(MyApp());
}为我工作过。
无需使用打开框和路径初始化,因为GraphQl在initHiveForFlutter内部处理这个问题。
https://stackoverflow.com/questions/68028023
复制相似问题