颤振框不会保存数据

问题描述

我正在尝试将记录的用户数据存储在 Hive 存储中,但我的用户框返回 null

代码

main.dart

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Hive.initFlutter();
  Hive.registeradapter(usermodelAdapter());
  await Hive.openBox<usermodel>('user');
  runApp(MyApp());
}

login.dart

用户通过服务器成功登录后,我尝试在重定向用户之前存储数据

print('Box:::: ${user.name}'); // print (admin) - user name coming from server

//store data in storage
var userData = usermodel()
  ..name = user.name
  ..email = user.email
  ..createdAt = user.createdAt
  ..approved = user.approved;
final Box = Hive.Box<usermodel>('user');
Box.add(userData);

print('Box:::: ${Box.get('name')}'); // print (null)

知道为什么我不能存储我的用户数据吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)