# Dart / Flutter

## **What is Dart?**

Dart is a programming language developed by Google that is designed for client and app development, such as desktop or mobile applications.

## **What is Flutter?**

Flutter is an open-source user interface development kit created for use with Dart. Flutter is used to develop mobile applications for Android and iOS, and desktop applications for Linux, Mac, Windows and Google.

Read below to learn how to configure a Dart or Flutter app to be used with Filebase.

{% hint style="success" %}

### Prerequisites:

* [x] Import the [minio-dart package](https://github.com/xtyxtyx/minio-dart) into your app.
* [x] [Sign up](https://filebase.com/signup) for a free Filebase account.&#x20;
* [x] Have your Filebase Access and Secret Keys. Learn how to view your access keys [here](https://docs.filebase.com/getting-started-guides/getting-started-guide#working-with-access-keys).
* [x] Create a Filebase Bucket. Learn how to create a bucket [here](< https://docs.filebase.com/getting-started-guides/getting-started-guide#creating-and-working-with-buckets>).
  {% endhint %}

{% hint style="warning" %}
Filebase is unable to provide specific configurations or debugging for custom applications due to their individualized nature.
{% endhint %}

### **Initialize the MinIO Client**

The following code example showcases how to initialize the MinIO Client using the minio-dart package. Replace the following values in the code to match your configuration:

* **accessKey**: Your Filebase Access Key
* **secretKey**: Your Filebase Secret Key

```dart
final minio = Minio(
	endPoint: 's3.filebase.com',
	accessKey: 'YOUR-ACCESSKEYID',
	secretKey: 'YOUR-SECRETACCESSKEY',
	useSSL: true,
);
```

### **Object Upload**

The following code example showcases how to upload an object using the minio-dart package. Replace the following values in the code to match your configuration:

* **accessKey**: Your Filebase Access Key
* **secretKey**: Your Filebase Secret Key
* **filebase-sample-bucket**: Your Filebase Bucket Name
* **myobject:** The Object Name to be Uploaded
* **/path/to/object**: The local path to the object

```dart
import 'package:minio/io.dart';
import 'package:minio/minio.dart';
void main() async {
	final minio = Minio(
		endPoint: 's3.filebase.com',
		accessKey: 'YOUR-ACCESSKEYID',
		secretKey: 'YOUR-SECRETACCESSKEY',
		useSSL: true,
);

await minio.fPutObject('filebase-sample-bucket', 'myobject', '/path/to/object');

}
```

### **Get Object**

The following code example showcases how to download an object using the minio-dart package. Replace the following values in the code to match your configuration:

* **accessKey**: Your Filebase Access Key
* **secretKey**: Your Filebase Secret Key
* **filebase-sample-bucket**: Your Filebase Bucket Name
* **myobject:** The Object Name to be downloaded.

```dart
import 'dart:io';
import 'package:minio/minio.dart';
void main() async {
	final minio = Minio(
		endPoint: 's3.filebase.com',
		accessKey: 'YOUR-ACCESSKEYID',
		secretKey: 'YOUR-SECRETACCESSKEY',
);

final stream = await minio.getObject('filebase-sample-bucket', 'myobject');

// Get object length
print(stream.contentLength);

// Write object data stream to file
await stream.pipe(File('output.txt').openWrite());

}
```

### **Full Example**

The following code example showcases a complete code example using the minio-dart package. Replace values as necessary to match your configuration.

```dart
import 'package:minio/io.dart';
import 'package:minio/minio.dart';
void main() async {
	final minio = Minio(
		endPoint: 's3.filebase.com',
		accessKey: 'YOUR-ACCESSKEYID',
		secretKey: 'YOUR-SECRETACCESSKEY',
		useSSL: true,
);
	final bucket = 'filebase-sample-bucket';
	final object = 'image.png';
	final copy1 = 'image.copy1.png';
	final copy2 = 'image.copy2.png';

	if (!await minio.bucketExists(bucket)) {
		await minio.makeBucket(bucket);
		print('bucket $bucket created');

	} else {
		print('bucket $bucket already exists');
}
	final poller = minio.listenBucketNotification(bucket, events: [
	's3:ObjectCreated:*',
]);
	poller.stream.listen((event) {
	print('--- event: ${event['eventName']}');
});
	final region = await minio.getBucketRegion('filebase-sample-bucket');
	print('--- object region:');
	print(region);
	
	final etag = await minio.fPutObject(bucket, object, 'example/$object');
	print('--- etag:');
	print(etag);

	final url = await minio.presignedGetObject(bucket, object, expires: 1000);
	print('--- presigned url:');
	print(url);

	final copyResult1 = await minio.copyObject(bucket, copy1, '$bucket/$object');
	final copyResult2 = await minio.copyObject(bucket, copy2, '$bucket/$object');
	print('--- copy1 etag:');
	print(copyResult1.eTag);
	print('--- copy2 etag:');
	print(copyResult2.eTag);

await minio.fGetObject(bucket, object, 'example/$copy1');
print('--- copy1 downloaded');

await minio.listObjects(bucket).forEach((chunk) {
print('--- objects:');

chunk.objects.forEach((o) => print(o.key));
});

await minio.listObjectsV2(bucket).forEach((chunk) {
print('--- objects(v2):');

chunk.objects.forEach((o) => print(o.key));
});

final stat = await minio.statObject(bucket, object);
print('--- object stat:');
print(stat.etag);
print(stat.size);
print(stat.lastModified);
print(stat.metaData);

await minio.removeObject(bucket, object);
print('--- object removed');

await minio.removeObjects(bucket, [copy1, copy2]);
print('--- copy1, copy2 removed');

await minio.removeBucket(bucket);
print('--- bucket removed');

poller.stop();
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.filebase.com/code-development-+-sdks/code-development/dart-flutter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
