Application/medcify/lib/storage/storage.dart
2022-09-26 12:03:52 +05:30

58 lines
2.1 KiB
Dart

import 'package:device_info_plus/device_info_plus.dart';
import 'package:medcify/models/api/login_response.dart';
import 'package:medcify/models/store_item.dart';
import 'package:medcify/network/api_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Storage{
Storage._();
static final Storage instance = Storage._();
late AndroidDeviceInfo deviceInfo;
late SharedPreferences sharedPreferences;
String razorpayKey = "";
String razorpaySecretKey = "";
Future<void> registerSharedPreferences() async{
final deviceInfoPlugin = DeviceInfoPlugin();
deviceInfo = await deviceInfoPlugin.androidInfo;
sharedPreferences = await SharedPreferences.getInstance();
}
Future<void> setIsLoggedIn(bool val) async{
await sharedPreferences.setBool("isLoggedIn", val);
}
Future<void> setMobile(String val) async{
await sharedPreferences.setString("mobile", val);
}
Future<void> setStoreUrl(String val) async{
await sharedPreferences.setString("storeUrl", val);
}
Future<void> setStoreId(int val) async{
await sharedPreferences.setInt("id", val);
}
Future<void> setUser(LoginResponse response) async{
await sharedPreferences.setBool("storeStatus", response.storeStatus ?? false);
await sharedPreferences.setString("token", response.token ?? "");
}
Future<void> fetchRazorPayData() async{
final response = await ApiProvider.instance.fetchRazorPayData();
if(response.status ?? false){
razorpayKey = response.razorPayKey ?? "";
razorpaySecretKey = response.razorPaySecretKey ?? "";
}
}
get isLoggedIn => sharedPreferences.getBool("isLoggedIn") ?? false;
get storeStatus => sharedPreferences.getBool("storeStatus") ?? false;
get mobile => sharedPreferences.getString("mobile") ?? "";
get storeUrl => sharedPreferences.getString("storeUrl") ?? "";
get id => sharedPreferences.getInt("id") ?? 0;
get token => sharedPreferences.getString("token") ?? "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImtrayIsImlhdCI6MTY0Mzg3MDM3M30.ddDwVEzkdQPGrJDqpz1XxU8PVaE7Zq3KkxxjZwukX8o";
}