Untitled
unknown
plain_text
3 years ago
3.1 kB
9
Indexable
import 'dart:developer';
import 'package:hayyu/constant/core/hive_const.dart';
import 'package:hayyu/modules/models/user.dart';
import 'package:hayyu/utils/services/firebase/function_firebase.dart';
import 'package:hayyu/utils/services/hive_service/hive_model/hive_data_login_model.dart';
import 'package:hive/hive.dart';
class HiveServices {
HiveServices._();
// String boxName;
static var authBox = Hive.box(HiveConstant.authBox);
/// SERVICE AUTH BOX
static Future<void> putAuth(String key, HiveDataLoginModel data) async {
await authBox.put(key, data);
}
static Future<void> deleteAuth(String key, data) async {
await authBox.delete(key);
}
/// SET ISFIRST COME FOR CHECKING SPLASH SCREEN
static Future<void> setFirstCome(String key, bool isFirstCome) async {
await authBox.put(key, isFirstCome);
}
static Future<bool> getFirstCome(String key) async {
var auth = Hive.box(HiveConstant.authBox);
var data = auth.get(HiveConstant.firstComeKey);
return data!;
}
static Future<void> setDeviceToken(String token) async {
await authBox.put(HiveConstant.deviceToken, token);
}
static Future<String?> getDeviceToken() async {
var auth = Hive.box(HiveConstant.authBox);
String? data = auth.get(HiveConstant.deviceToken);
return data;
}
/// SET TO HIVE ,SERVER SELECTED VALUE
static Future<void> setServer(String serverSelected) async {
await authBox.put(HiveConstant.serverKey, serverSelected);
}
static Future<String?> getServer() async {
var auth = Hive.box(HiveConstant.authBox);
var data = auth.get(HiveConstant.serverKey);
return data;
}
static Future<void> clearServer() async {
var auth = Hive.box(HiveConstant.authBox);
auth.delete(HiveConstant.serverKey);
}
static Future<HiveDataLoginModel?> getLoginData() async {
var auth = Hive.box(HiveConstant.authBox);
var data = auth.get(HiveConstant.authKey);
return data;
}
static Future<void> setLoginData(User? user) async {
User? authUser = user;
log("ID USER => LOG IN HIVE SERVICE : ${user!.id}");
HiveDataLoginModel hiveUser = HiveDataLoginModel()
..id = authUser?.id
..nama = authUser?.nama
..email = authUser?.email
..telp = authUser?.telp
..kodeReferal = authUser?.kodeReferal
..noMember = authUser?.noMember
..fotoProfile = authUser?.fotoProfile
..device = authUser?.device
..versiAplikasi = authUser?.versiAplikasi
..qiscusId = authUser?.qiscusId
..qiscusIdBantuan = authUser?.qiscusIdBantuan
..namaPasien = authUser?.namaPasien
..telpPasien = authUser?.telpPasien
..emailQiscus = authUser?.emailQiscus
..namaAgent = authUser?.namaAgent
..qiscusAgentId = authUser?.qiscusAgentId
..qiscusAgentEmail = authUser?.qiscusAgentEmail
..qiscusAvatar = authUser?.qiscusAvatar
..qiscusCustomerAvatar = authUser?.qiscusCustomerAvatar;
await putAuth(HiveConstant.authKey, hiveUser);
await subscribeNotif();
await subscribeNotifGlobal();
}
}
Editor is loading...