getSubscriber method

Future<SubscriberModel> getSubscriber()

Implementation

Future<SubscriberModel> getSubscriber() async {
  SharedPreferences sharedPreferences = await DeviceStorage().getInstance();
  String? subscriberData =
      sharedPreferences.getString(DeviceStorage.subscriberData);
  if (subscriberData == null || subscriberData.isEmpty) {
    subscriberData = await NetworkHandler.getSubscriber();
    if (subscriberData.isEmpty) {
      throw Exception("User not logged in");
    }
    await sharedPreferences.setString(
        DeviceStorage.subscriberData, subscriberData);
  }
  SubscriberModel subscriberModel =
      SubscriberModel.fromMap(jsonDecode(subscriberData));

  return subscriberModel;
}