downloadFontModel method

  1. @override
Future<SDKPublishFont?> downloadFontModel({
  1. required String projectID,
  2. required String fontID,
  3. required PublishSource source,
})
override

Fetches the relevant SDKPublishFont from the server based on the configurations of the implementation.

Implementation

@override
Future<SDKPublishFont?> downloadFontModel({
  required String projectID,
  required String fontID,
  required PublishSource source,
}) async {
  try {
    final Response result = await post(
      Uri.parse(
          '${config.firebaseCloudFunctionsBaseURL}/api/getFontModelRequest'),
      headers: <String, String>{'Content-Type': 'application/json'},
      body: jsonEncode({
        'projectID': projectID,
        'fontID': fontID,
        'source': source.serverPath,
      }),
      encoding: utf8,
    );

    if (result.statusCode != 200) {
      log('[WebDataRepo] Error downloading font model.');
      log('[WebDataRepo] Status code: ${result.statusCode}');
      log('[WebDataRepo] Message: ${result.body}');
      throw CodelesslyException(
        'Error downloading font model.',
        stacktrace: StackTrace.current,
      );
    }
    final Map<String, dynamic> modelDoc = jsonDecode(result.body);
    final SDKPublishFont font = SDKPublishFont.fromJson(modelDoc);

    return font;
  } catch (e) {
    return null;
  }
}