Back to Blog
Company

Announcing Nhost SDK for Flutter

11 May 2021
Transparent lines
Banner of Announcing Nhost SDK for Flutter

Finally, it's easy for flutter developers to build full-stack apps. The Dart & Flutter SDK for Nhost makes it easy to handle authentication, storage and GraphQL in any Flutter application.

Nhost is a Firebase alternative built on open source software. With a Nhost project you get a Postgres database. On top of the database we automatically generate a GraphQL API based on your tables and columns in your database. Nhost also handles authentication and storage.

This enables developers to focus on their app and users, instead of building and managing infrastructure.

Our new Flutter SDK makes it easy for Flutter developers to build rich applications.

GraphQL

Our Flutter SDK integrates with graphql, currently the most popular GraphQL client for Dart, meaning users are automatically authenticated when sending GraphQL requests in the app.

Our Flutter SDK also connects to graphql_flutter to generate GraphQL widgets.

See full examples here.

Authentication

Register and login your users in your Flutter application:


_11
// Setupfinal client = NhostClient(baseUrl: nhostApiUrl);
_11
_11
// Login
_11
await loginOrRegister(client, email: 'user-1@nhost.io', password: 'password-1');
_11
_11
// Print out a few details about the current userfinal currentUser = client.auth.currentUser;
_11
print('currentUser.id: ${currentUser.id}');
_11
print('currentUser.displayName: ${currentUser.displayName}');
_11
print('currentUser.email: ${currentUser.email}');
_11
_11
// And logoutawait client.auth.logout();

See full auth examples here.

Storage

Let users upload and download files in your Flutter application:


_22
final fileName = 'henry.jpg';
_22
final userPath = '/user/${client.auth.currentUser.id}/';
_22
final filePath = '$userPath$fileName';
_22
_22
// Store a new image file...final originalImageBytes = File('./assets/henry.jpg').readAsBytesSync();
_22
final imageMetadata = await client.storage.uploadBytes(
_22
filePath: filePath,
_22
bytes: originalImageBytes,
_22
contentType: 'image/jpeg',
_22
);
_22
print('Uploaded image');
_22
print('Size: ${originalImageBytes.length}');
_22
_22
// ...turn around and download its contents, scaled...final downloadedImage = await client.storage.downloadImage(
_22
filePath,
_22
fileToken: imageMetadata.nhostMetadata.token,
_22
imageTransformConfig: ImageTransformConfig(width: 100, quality: 50),
_22
);
_22
print('Downloaded transformed image');
_22
print('Size: ${downloadedImage.bodyBytes.length}');
_22
_22
// ...then delete it.await client.storage.delete(filePath);

See full storage examples here and here.

Share this post

Twitter LogoLinkedIn LogoFacebook Logo