submitApi function

Future<void> submitApi(
  1. String gameKey,
  2. String gameSettingsId,
  3. String event,
  4. Map? properties,
  5. String token,
  6. String baseUrl,
)

Implementation

Future<void> submitApi(String gameKey, String gameSettingsId, String event,
    Map<dynamic, dynamic>? properties, String token, String baseUrl) async {
  try {
    var headers = {
      'Authorization': token,
      'Content-Type': 'application/json',
    };
    var request = http.Request(
      'POST',
      Uri.parse('$baseUrl/generic_submit/submit'),
    );

    request.body = json.encode({
      "event": event,
      "gameKey": gameKey,
      "gameSettingsId": gameSettingsId,
      "props": properties ?? {}
    });
    request.headers.addAll(headers);
    print("called submit:");
    http.StreamedResponse response = await request.send();
    print("Response:");
    print(response.toString());
    if (response.statusCode == 200) {
      print(await response.stream.bytesToString());
    } else {
      throw Exception(response.reasonPhrase);
    }
  } catch (e, st) {
    print(st);
    print(e);
    throw Exception('Failed to update data');
  }
}