findOne static method

Future<Map<String, dynamic>> findOne({
  1. required String collection,
  2. required String id,
})

gets a single object in a collection with id, throws StrapiResponseException if response is failed

Implementation

static Future<Map<String, dynamic>> findOne(
    {required String collection, required String id}) async {
  StrapiObjectListener._informLoading(id);
  final path = collection + "/" + id;
  final response = await Strapi.i.request(
    path,
  );
  if (response.failed) {
    throw StrapiResponseException(
      "failed to get single object from collection $collection",
      response,
    );
  }
  if (!response.failed) {
    StrapiObjectListener._inform(response.body);
  }
  return response.body.first;
}