Nhost Dart SDK

Pub nhost_dart tests

Nhost authentication and file storage API clients for Dart and Flutter.

Includes support for:

  • User sign in and registration, including multi-factor authentication
  • Email and password changes, either directly or via email confirmation
  • Storage and retrieval of arbitrary files
  • Scaling and transformation of stored files
  • GraphQL authentication, via nhost_graphql_adapter

Sample

import 'dart:typed_data';
import 'package:nhost_dart/nhost_dart.dart';
import 'package:nhost_storage_dart/nhost_storage_dart.dart' show FileData;

void main() async {
  final nhost = NhostClient(
    subdomain: Subdomain(
      region: 'eu-central-1',
      subdomain: 'backend-5e69d1d7',
    ),
  );

  // For self-hosted or local projects, use ServiceUrls instead.
  /*
  final nhost = NhostClient(
    serviceUrls: ServiceUrls(
      authUrl: 'http://localhost:1337/v1/auth',
      storageUrl: 'http://localhost:1337/v1/storage',
      functionsUrl: 'http://localhost:1337/v1/functions',
      graphqlUrl: 'http://localhost:1337/v1/graphql',
    ),
  );
  */

  // User registration
  final authResponse = await nhost.auth.signUp(
    email: 'new-user@gmail.com',
    password: 'password-1',
  );

  // Upload a file
  final currentUser = authResponse.user ?? nhost.auth.currentUser;
  await nhost.storage.uploadBytes(
    fileName: '/users/${currentUser!.id}/image.jpg',
    fileContents: [/* ... */],
    mimeType: 'image/jpeg',
  );

  // Log out
  await nhost.auth.signOut();

  // Release resources
  nhost.close();
}

Getting Started

Latest Release

dependencies:
  nhost_dart: ^2.2.0

🔥 More Dart & Flutter packages from Nhost

Libraries

nhost_dart