phoenix_wings 0.1.2

  • Example
  • Installing
  • Versions
  • 76


A Phoenix Channel implementation for Dart

Attempts to feature match the Javascript implementation found at phoenix.js


Much of the library is the same whether your code is running in the VM/Flutter or in a browser. Due to differences between the two platforms, the connection setup differs slightly.

Import & Connection (VM/Flutter)

import 'package:phoenix_wings/phoenix_wings.dart';

final socket = new PhoenixSocket("ws://localhost:4000/websocket/socket");

// equivalent to passing connectionProvider: PhoenixIoConnection.provider

Import & Connection (HTML)

import 'package:phoenix_wings/html.dart';

final socket = new PhoenixSocket("ws://localhost:4000/websocket/socket", connectionProvider: PhoenixHtmlConnection.provider);

Common Usage

await socket.connect();

final chatChannel ="room:chat", {"id": "myId"});

chatChannel.on("user_entered", PhoenixMessageCallback (Map payload, String _ref, String, _joinRef) {



Most of the tests are run on the VM. However, the PhoenixHtmlConnection tests must run in a browser. You can use the following commands to run all tests for both platforms:

    # using firefox
    pub run test test/ -p vm,firefox

    # using chrome
    pub run test test/ -p vm,chrome

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.


import 'package:flutter/material.dart';
import 'package:phoenix_wings/phoenix_wings.dart';
import 'package:intl/intl.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
      home: MyHomePage(title: 'Phoenix Wings Chat'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  final socket = PhoenixSocket("ws://localhost:4000/socket/websocket");

  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  PhoenixChannel _channel;
  List<ChatMessage> messages = [];
  final TextEditingController _textController = TextEditingController();

  void initState() {

  connectSocket() async {
    await widget.socket.connect();
    // Create a new PhoenixChannel
    _channel ="flutter_chat:lobby");
    // Setup listeners for channel events
    _channel.on("say", _say);

    // Make the request to the server to join the channel

  _say(payload, _ref, _joinRef) {
    setState(() {
      messages.insert(0, ChatMessage(text: payload["message"]));

  _sendMessage(message) {
    _channel.push(event: "say", payload: {"message": message});

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      body: Column(
        children: <Widget>[
            child: ListView.builder(
              reverse: true,
              itemBuilder: (BuildContext context, int index) {
                final message = messages[index];
                return Card(
                    child: Column(
                  children: <Widget>[
                        leading: Icon(Icons.message),
                        title: Text(message.text),
                        subtitle: Text(message.time)),
              itemCount: messages.length,
            height: 1.0,
              child: MessageComposer(
            textController: _textController,
            sendMessage: _sendMessage,

class ChatMessage {
  final String text;
  final DateTime received =;

  get time => DateFormat.Hms().format(received);

class MessageComposer extends StatelessWidget {
  final textController;
  final sendMessage;

  MessageComposer({this.textController, this.sendMessage});
  build(BuildContext context) {
    return Container(
        margin: EdgeInsets.symmetric(horizontal: 8.0),
        child: Row(
          children: <Widget>[
              child: TextField(
                  controller: textController,
                  onSubmitted: sendMessage,
                      InputDecoration.collapsed(hintText: "Send a message")),
              child: IconButton(
                  icon: Icon(Icons.send),
                  onPressed: () => sendMessage(textController.text)),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  phoenix_wings: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:phoenix_wings/phoenix_wings.dart';
Version Uploaded Documentation Archive
0.1.2 May 20, 2018 Go to the documentation of phoenix_wings 0.1.2 Download phoenix_wings 0.1.2 archive
0.0.3 Jan 1, 2018 Go to the documentation of phoenix_wings 0.0.3 Download phoenix_wings 0.0.3 archive
0.0.2 Dec 30, 2017 Go to the documentation of phoenix_wings 0.0.2 Download phoenix_wings 0.0.2 archive
0.0.1 Dec 29, 2017 Go to the documentation of phoenix_wings 0.0.1 Download phoenix_wings 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5


Detected platforms: unsure

References Flutter, but has conflicting libraries: package:phoenix_wings/html.dart (components: html, io).

Health suggestions

Fix lib/src/phoenix_io_connection.dart. (-1 points)

Analysis of lib/src/phoenix_io_connection.dart reported 2 hints:

line 18 col 58: 'OPEN' is deprecated and shouldn't be used.

line 19 col 56: 'CLOSED' is deprecated and shouldn't be used.

Format lib/html.dart.

Run flutter format to format lib/html.dart.

Format lib/src/phoenix_channel.dart.

Run flutter format to format lib/src/phoenix_channel.dart.

Fix additional 7 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/phoenix_connection.dart (Run flutter format to format lib/src/phoenix_connection.dart.)
  • lib/src/phoenix_html_connection.dart (Run flutter format to format lib/src/phoenix_html_connection.dart.)
  • lib/src/phoenix_message.dart (Run flutter format to format lib/src/phoenix_message.dart.)
  • lib/src/phoenix_push.dart (Run flutter format to format lib/src/phoenix_push.dart.)
  • lib/src/phoenix_serializer.dart (Run flutter format to format lib/src/phoenix_serializer.dart.)
  • lib/src/phoenix_socket.dart (Run flutter format to format lib/src/phoenix_socket.dart.)
  • lib/src/phoenix_socket_options.dart (Run flutter format to format lib/src/phoenix_socket_options.dart.)

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

References Flutter, but has conflicting libraries: package:phoenix_wings/html.dart (components: html, io).

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.2.3 <3.0.0
Dev dependencies
dartdoc 0.19.0
intl ^0.15.6
mockito ^2.2.1
stream_channel ^1.6.4
test 0.12.37