---
title: "Introducing the Ably Flutter plugin"
url: "https://ably.com/blog/ably-flutter-plugin"
canonical: "https://ably.com/blog/ably-flutter-plugin"
description: "The Ably Flutter Plugin makes it easy for developers to add WebSocket-based pub/sub messaging to their Flutter applications."
author: "Srushtika Neelakantam"
published: "2021-01-20"
updated: "2023-08-24"
tags: ["Ably news"]
---

# Introducing the Ably Flutter plugin

Today, we’re pleased to support Flutter’s growing community of builders by releasing [Ably’s Flutter plugin v1.0](https://pub.dev/packages/ably%5Fflutter). This makes it easy for developers to add [WebSocket-based pub/sub messaging to their Flutter applications](https://www.ably.io/topic/websockets-flutter).

Flutter has grown incredibly over the past few years, providing a platform to build modern applications. Increasingly, developers are looking to build event-driven applications where user interactions play out in realtime. That’s where Ably’s Flutter plugin comes in.

Read on to know everything about it or scroll down to the last section to get started.

## What is Flutter?

[Flutter](https://flutter.dev/) is an open-sourced UI toolkit by Google that allows a single codebase to compile for both Android and iOS platforms. This means less code, less time but a wider audience. Ah, every app developer's dream.

![Flutter homepage](https://ik.imagekit.io/ably/ghost/prod/2021/01/Screenshot-2021-01-13-at-11.39.54.png)

_[Flutter's homepage](https://flutter.dev/)_

Flutter apps are written in [Dart](https://dart.dev/), a strongly-typed object-oriented programming language, also by Google. With its C-style syntax and borrowed concepts from many other languages like Java, C# and JavaScript, Dart did receive a bit of criticism when it was initially unveiled in 2013\. But thanks to Flutter, the tide has turned and it's now picked up pace.

## About the Ably Flutter plugin

The [Ably Flutter plugin](https://github.com/ably/ably-flutter) brings realtime magic to the much loved Flutter ecosystem. If you are new to [Ably](https://www.ably.io/), here's a quick summary of what we do:

- We provide a scalable, pub/sub messaging infrastructure that you can use on any platform and with any programming language (Seriously, there are work-arounds for any SDKs or platforms that we don't yet directly support).
- While Ably primarily operates over WebSockets, you have the flexibility of choosing between WebSockets, MQTT or Server-Sent Events (SSE) based on the best-suited conditions for the platform on which you intend to run your app.
- Our pub/sub messaging service comes pre-engineered with a full suite of additional features like message-ordering, guaranteed delivery, webhook powered integrations with third-party apps and platforms, and many more. We provide everything you need for any realtime application.

The [Ably Flutter plugin](https://github.com/ably/ably-flutter) is a wrapper around our fully-featured [Cocoa](https://github.com/ably/ably-cocoa) and [Java](https://github.com/ably/ably-java) client library SDKs, providing iOS and Android support for those using Flutter and Dart.

The plugin is fully open-sourced and is still a work in progress. While it already supports the major Ably functionality, i.e.[ Pub/Sub messaging](https://www.ably.io/documentation/realtime/usage), other features like [Presence](https://www.ably.io/documentation/realtime/presence) \- which is useful to find out the online/ connection status of a client, and [Message History](https://www.ably.io/documentation/realtime/history) \- which is useful to retrieve historical messages up to a certain point in time, are soon to come. You can [follow the project on GitHub](https://pub.dev/packages/ably%5Fflutter) (please feel free to contribute) for updates and roadmap.

### See it working in a chat app

While I focus my dev days mostly on web apps and NodeJS backends, the enormous popularity of Flutter intrigued me to try it out. I found a [YouTube video by Marcus Ng about Flutter chat UI kit](https://www.youtube.com/watch?v=h-igXZCCrrc) and decided to add realtime messaging to it with the Ably Flutter plugin and bring the chat app to life. 10min well spent and I had a production-ready chat app.

You can check out the [full source code for this chat app on GitHub](https://github.com/ably-labs/flutter-chat-demo). I also made a video explaining the key parts:

[Embedded content](https://www.youtube.com/embed/wwytqIh8km0?feature=oembed)

_Chat app built with the Ably Flutter plugin_

The whole realtime messaging part in the chat app comes down to three main things - Initialize Ably, Publish and Subscribe:

```dart
  void subscribeToChatChannel() {
    var messageStream = chatChannel.subscribe();
    messageStream.listen((ably.Message message) {
      Message newChatMsg = message.data;
      .
      .
      .
      setState(() {
        messages.insert(0, newChatMsg);
      });
    });
  }

```

_Subscribe to the chat channel_

```dart
  void createAblyRealtimeInstance() async {
    var clientOptions = ably.ClientOptions.fromKey(AblyAPIKey);
    try {
      realtimeInstance = ably.Realtime(options: clientOptions);
      chatChannel = realtimeInstance.channels.get('flutter-chat');
      subscribeToChatChannel();
    } catch (error) {
      print('Error creating Ably Realtime Instance: $error');
      rethrow;
    }
  }
```

_Initialize Ably_

```dart
  void publishMyMessage() async {
    var myMessage = myInputController.text;
    myInputController.clear();
    chatChannel.publish(name: "chatMsg", data: {
      "sender": "randomChatUser",
      "text": myMessage,
    });
  }
```

_Publish to the chat channel_

[![Try our APIs for free](https://no-cache.hubspot.com/cta/default/6939709/85f436af-7315-44c9-aa12-d764f40b294d.png)](https://cta-redirect.hubspot.com/cta/redirect/6939709/85f436af-7315-44c9-aa12-d764f40b294d)
  
Simple as that. 

Don't worry, we also have an in-depth step-by-step tutorial written by Flutter experts for you to follow along, more on this later...

## How do I get started? 

**1\. Check it out on pub.dev (and give it a thumbs up!)**

The [Ably Flutter plugin is available as a package on pub.dev](https://pub.dev/packages/ably%5Fflutter). Just look for `ably_flutter_plugin`. After adding it to your `pubscpec.yaml` file and running `` `flutter packages get` ``, you will be able to import Ably in your project files like so:

```dart
import 'package:ably_flutter_plugin/ably_flutter_plugin.dart' as ably;
```

**2\. Dive into the docs**

Check out the official [Ably documentation](https://www.ably.io/documentation) to learn more about the various methods and features available and integrate the [Flutter Plugin with the Quickstart Guide](https://www.ably.io/documentation/quick-start-guide?lang=flutter). On any page with code snippets, you should be able to switch to the Flutter version of the docs by choosing the language from the navbar on the top right.

**3\. Follow an in-depth tutorial — Building a Realtime Cryptocurrency App with Flutter**

We invited two Google Developer Experts for Flutter - [Mais Alheraki](https://twitter.com/pr%5FMais) and [Thomas Burkhart](https://twitter.com/ThomasBurkhartB) \- to try out the Ably Flutter plugin. They built a beautiful cryptocurrency app that you see below and wrote a [step-by-step tutorial](https://www.ably.io/tutorials/realtime-cryptocurrency-app-flutter) for you to follow along. You can also [check out the full source code for this app on GitHub](https://github.com/ably-labs/live-cryptocurrency-streaming-flutter).

![](https://ik.imagekit.io/ably/ghost/prod/2021/01/final-60056caefcfaec005241a18d-1.gif)

_[Building a cryptocurrency app in Flutter](https://www.ably.io/tutorials/realtime-cryptocurrency-app-flutter)_

## Conclusion

We're excited to see what you build with this plugin. Send your creations our way ([@ablyrealtime](https://twitter.com/ablyrealtime)) and we'll be happy to share it around and give a shoutout.

If you have any questions or ideas, feel free to [reach out to us](https://www.ably.io/contact).
