listBuckets method Null safety

Future<StorageResponse<List<Bucket>>> listBuckets()
inherited

Retrieves the details of all Storage buckets within an existing product.

Implementation

Future<StorageResponse<List<Bucket>>> listBuckets() async {
  try {
    final FetchOptions options = FetchOptions(headers: headers);
    final response = await fetch.get('$url/bucket', options: options);
    if (response.hasError) {
      return StorageResponse(error: response.error);
    } else {
      final buckets = List<Bucket>.from(
        (response.data as List).map(
          (value) => Bucket.fromJson(value),
        ),
      );
      return StorageResponse<List<Bucket>>(data: buckets);
    }
  } catch (e) {
    return StorageResponse(error: StorageError(e.toString()));
  }
}