createBucket method Null safety

Future<String> createBucket(
  1. String id,
  2. [BucketOptions bucketOptions = const BucketOptions(public: false)]
)
inherited

Creates a new Storage bucket

id is a unique identifier for the bucket you are creating.

bucketOptions is a parameter to optionally make the bucket public.

It returns the newly created bucket it. To get the bucket reference, use getBucket:

void bucket() async {
  final newBucketId = await createBucket('images');
  final bucket = await Bucket(newBucketId);
  print('${bucket.id}');
}

Implementation

Future<String> createBucket(
  String id, [
  BucketOptions bucketOptions = const BucketOptions(public: false),
]) async {
  final FetchOptions options = FetchOptions(headers: headers);
  final response = await storageFetch.post(
    '$url/bucket',
    {'id': id, 'name': id, 'public': bucketOptions.public},
    options: options,
  );
  final bucketId = (response as Map<String, dynamic>)['name'] as String;
  return bucketId;
}