getAnnouncement method

Future<Map<String, List<Announcement>>?> getAnnouncement({
  1. required String gitHubUsername,
  2. required String hashCode,
  3. required String tag,
  4. GeneralCallback<Map<String, List<Announcement>?>>? callback,
})

Implementation

Future<Map<String, List<Announcement>>?> getAnnouncement({
  required String gitHubUsername,
  required String hashCode,
  required String tag,
  GeneralCallback<Map<String, List<Announcement>?>>? callback,
}) async {
  try {
    final Response<String> response = await dio.get(
      '$basePath/$gitHubUsername/$hashCode/raw/'
      '${tag}_announcement.json',
    );
    final Map<String, List<Announcement>?> map =
        <String, List<Announcement>>{};
    final dynamic json = jsonDecode(response.data!);
    if (json is Map<String, Map<String, dynamic>>) {
      json.forEach((String key, Map<String, dynamic> data) {
        if (key != 'data') {
          map[key] = AnnouncementData.fromJson(data).data;
        }
      });
    }
    return callback?.onSuccess(map) as Map<String, List<Announcement>>;
  } on DioException catch (e) {
    if (callback != null) {
      callback.onFailure(e);
    } else {
      rethrow;
    }
  } on Exception catch (_) {
    callback?.onError(GeneralResponse.unknownError());
    rethrow;
  }
  return null;
}