getAnnouncement method

Future<Announcement?> getAnnouncement({
  1. required int id,
  2. String? locale,
  3. GeneralCallback<Announcement>? callback,
})

Implementation

Future<Announcement?> getAnnouncement({
  required int id,
  String? locale,
  GeneralCallback<Announcement>? callback,
}) async {
  try {
    final Response<Map<String, dynamic>> response = await dio.get(
      '/announcements/$id',
    );
    final Announcement data = Announcement.fromJson(
      response.data!['data'] as Map<String, dynamic>,
    );
    if (callback != null) {
      callback.onSuccess(data);
    }
    return data;
  } on DioException catch (dioException) {
    if (callback == null) {
      rethrow;
    } else {
      callback.onFailure(dioException);
    }
  }
  return null;
}