phoenix_wings 0.1.2

  • Example
  • Installing
  • Versions
  • 75


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


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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4


Describes how popular the package is relative to other packages. [more]
59 / 100
Code health derived from static analysis. [more]
98 / 100
Reflects how tidy and up-to-date the package is. [more]
80 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: unsure

References Flutter, but has conflicting libraries: package:phoenix_wings/html.dart.


  • Fix platform conflicts.

    References Flutter, but has conflicting libraries: package:phoenix_wings/html.dart.

  • The description is too short.

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

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 12 hints.

    Run flutter format to format lib/html.dart.

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

    Similar analysis of the following files failed:

    • lib/src/phoenix_connection.dart (hint)
    • lib/src/phoenix_html_connection.dart (hint)
    • lib/src/phoenix_io_connection.dart (hint)
    • lib/src/phoenix_message.dart (hint)
    • lib/src/phoenix_push.dart (hint)
    • lib/src/phoenix_serializer.dart (hint)
    • lib/src/phoenix_socket.dart (hint)
    • lib/src/phoenix_socket_options.dart (hint)
  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.


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