fetchAppearance function

Future<ApiBaseResponse<DWalletAppearance>> fetchAppearance(
  1. String refererKey
)

Implementation

Future<ApiBaseResponse<DWalletAppearance>> fetchAppearance(
    String refererKey) async {
  final url = BaseUrl.baseUrl! + api().getConfig;

  final Map<String, String> headers = {
    'token': envDemo().token,
    'Content-Type': 'application/json',
    'X-Referrer-Key': refererKey,
  };

  try {
    final jsonData = await http.get(
      Uri.parse(url),
      headers: headers,
    );

    if (jsonData.statusCode == 200) {
      print("${jsonData.body}");
      final Map<String, dynamic> decodedJson = jsonDecode(jsonData.body);

      final response = ApiBaseResponse<DWalletAppearance>.fromJson(
        decodedJson,
        (dataJson) => DWalletAppearance.fromJson(dataJson),
      );

      return response;
    } else {
      throw Exception('Failed to load data from API');
    }
  } catch (ex) {
    print("$ex");

    throw Exception('Failed to load data from API ${ex.toString()}');
  }
}