Announcing Nhost SDK for Flutter
11 May 2021Finally, 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_11await 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;_11print('currentUser.id: ${currentUser.id}');_11print('currentUser.displayName: ${currentUser.displayName}');_11print('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:
_22final fileName = 'henry.jpg';_22final userPath = '/user/${client.auth.currentUser.id}/';_22final filePath = '$userPath$fileName';_22_22// Store a new image file...final originalImageBytes = File('./assets/henry.jpg').readAsBytesSync();_22final imageMetadata = await client.storage.uploadBytes(_22filePath: filePath,_22bytes: originalImageBytes,_22contentType: 'image/jpeg',_22);_22print('Uploaded image');_22print('Size: ${originalImageBytes.length}');_22_22// ...turn around and download its contents, scaled...final downloadedImage = await client.storage.downloadImage(_22filePath,_22fileToken: imageMetadata.nhostMetadata.token,_22imageTransformConfig: ImageTransformConfig(width: 100, quality: 50),_22);_22print('Downloaded transformed image');_22print('Size: ${downloadedImage.bodyBytes.length}');_22_22// ...then delete it.await client.storage.delete(filePath);