62 lines
1.4 KiB
Dart
62 lines
1.4 KiB
Dart
import 'package:hive/hive.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
class HiveManager {
|
|
static Box? _userInfoBox;
|
|
|
|
static Future<void> initHive() async {
|
|
final dir = await getApplicationDocumentsDirectory();
|
|
Hive.defaultDirectory = dir.path;
|
|
|
|
_userInfoBox = Hive.box();
|
|
}
|
|
|
|
static void clearLoginInfo() {
|
|
_userInfoBox?.delete('token');
|
|
_userInfoBox?.delete('shopId');
|
|
_userInfoBox?.delete('shopName');
|
|
_userInfoBox?.delete('shopLogo');
|
|
_userInfoBox?.delete('userInfo');
|
|
}
|
|
|
|
static void setUserToken(String token) {
|
|
_userInfoBox?.put('token', token);
|
|
}
|
|
|
|
static String getUserToken() {
|
|
return _userInfoBox?.get('token') ?? '';
|
|
}
|
|
|
|
static void setShopId(String shopId) {
|
|
_userInfoBox?.put('shopId', shopId);
|
|
}
|
|
|
|
static String getShopId() {
|
|
return _userInfoBox?.get('shopId') ?? '';
|
|
}
|
|
|
|
static void setShopName(String shopName) {
|
|
_userInfoBox?.put('shopName', shopName);
|
|
}
|
|
|
|
static String getShopName() {
|
|
return _userInfoBox?.get('shopName') ?? '';
|
|
}
|
|
|
|
static void setShopLogo(String shopLogo) {
|
|
_userInfoBox?.put('shopLogo', shopLogo);
|
|
}
|
|
|
|
static String getShopLogo() {
|
|
return _userInfoBox?.get('shopLogo') ?? '';
|
|
}
|
|
|
|
static void setUserInfo(String userInfo) {
|
|
_userInfoBox?.put('userInfo', userInfo);
|
|
}
|
|
|
|
static String getUserInfo() {
|
|
return _userInfoBox?.get('userInfo') ?? '';
|
|
}
|
|
}
|