getBranchLink function

Future<String> getBranchLink(
  1. String template
)

Implementation

Future<String> getBranchLink(String template) async {
  try {
    final response = await http.post(
      Uri.parse(Constants.RECLAIM_GET_BRANCH_URL),
      headers: <String, String>{
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: jsonEncode({
        'template': template,
      }),
    );
    if (response.statusCode == 200) {
      final decodedResponse = jsonDecode(response.body);
      final link = decodedResponse['branchUrl'];
      if (link == null) {
        throw Exception('Failed to generate deep link');
      }
      return link;
    } else {
      throw Exception('Failed to generate deep link: ${response.statusCode}');
    }
  } catch (error) {
    rethrow;
  }
}