Skip to content
pubscout

dart_nats

1.7.1, released 2 weeks ago by an unverified publisher

A Dart and Flutter client library for the NATS messaging system.

WASM-ready
$ flutter pub add dart_nats
Source repository

What it does

Allows Dart and Flutter applications to communicate with NATS messaging servers. Supports publish-subscribe, request-reply patterns, JetStream persistence, and multiple authentication methods across TCP and WebSockets.

AI-written summary of version 1.7.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to connect a Flutter app or Dart service to a NATS messaging cluster
  • You require real-time pub/sub or request-reply messaging patterns
  • You want support for WebSockets on the web and raw TCP sockets on native platforms

Skip it when

  • Your backend is built around HTTP/REST or GraphQL without a NATS intermediary
  • You are looking for a general-purpose state management or local storage solution

Strengths

  • Supports both TCP and WebSocket transports for native and web platforms
  • Includes robust connection lifecycle management, background retries, and heartbeats
  • Offers advanced features like queue groups, wildcard subscriptions, and experimental JetStream support

Weaknesses

  • JetStream, Key-Value, and Object Store APIs are currently experimental
  • Requires a running NATS server infrastructure to be useful

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5

Add the dependency to pubspec.yaml and connect using a NATS server URI.

final client = Client();
await client.connect(Uri.parse('nats://localhost:4222'));
final sub = client.sub('sensors.temperature');
sub.stream.listen((Message msg) {
  print('Received payload: ${msg.string}');
});

Alternatives

Packages that do the same job and could replace dart_nats.

Works with

Packages commonly used together with dart_nats: ones it builds on, ones built on it, and its own family.