stream_chat 0.1.30

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

Stream Chat Dart #

Pub CI codecov

stream-chat-dart is the official Dart client for Stream Chat, a service for building chat applications. This library can be used on any Dart project and on both mobile and web apps with Flutter.

You can sign up for a Stream account at https://getstream.io/chat/

Getting started #

Add dependency #

dependencies:
 stream_chat: ^0.1.21

You should then run flutter packages get

Alpha version #

Use version ^0.2.0-alpha to use the latest available version.

Note that this is still an alpha version. There may be some bugs and the api can change in breaking ways.

Thanks to whoever tries these versions and reports bugs or suggestions.

Example Project #

There is a detailed Flutter example project in the example folder. You can directly run and play on it.

At this link you can find the example compiled with Hummingbird

Setup API Client #

First you need to instantiate a chat client. The Chat client will manage API call, event handling and manage the websocket connection to Stream Chat servers. You should only create the client once and re-use it across your application.

var client = Client("stream-chat-api-key");

Logging #

By default the Chat Client will write all messages with level Warn or Error to stdout.

Change Logging Level

During development you might want to enable more logging information, you can change the default log level when constructing the client.

var client = Client("stream-chat-api-key", logLevel: Level.INFO);

Custom Logger

You can handle the log messages directly instead of have them written to stdout, this is very convenient if you use an error tracking tool or if you want to centralize your logs into one facility.

myLogHandlerFunction = (LogRecord record) {
  // do something with the record (ie. send it to Sentry or Fabric)
}

var client = Client("stream-chat-api-key", logHandlerFunction: myLogHandlerFunction);

Contributing #

Code conventions #

  • Make sure that you run dartfmt before commiting your code
  • Make sure all public methods and functions are well documented

Running tests #

Releasing a new version #

  • update the package version on pubspec.yaml and version.dart

  • add a changelog entry on CHANGELOG.md

  • run flutter pub publish to publish the package

Watch models and generate JSON code #

JSON serialization relies on code generation; make sure to keep that running while you make changes to the library

flutter pub run build_runner watch

0.1.30 #

  • Add silent property to message

0.1.29 #

  • Fix read event handling

0.1.28 #

  • Fix bug clearing members when receiving a message

0.1.27 #

  • Update dependencies

0.1.26 #

  • Remove wrong members property from ChannelModel

0.1.25 #

  • Fix online status

0.1.24 #

  • Fix unread count

0.1.22 #

  • Add mute/unmute channel

0.1.20 #

  • Fix channel query path without id

0.1.19 #

  • Fix loading message replies

0.1.18 #

  • Export dio error

0.1.17 #

  • Ignore current user typing events

  • Add event types

0.1.16 #

  • Fix message update

0.1.15 #

  • Fix mentions handling

0.1.14 #

  • Handle message modification and commands

0.1.13 #

  • Add message.updated event handling

0.1.12 #

  • Add export multipart_file from dio

0.1.11 #

  • Add channel config checks

0.1.10 #

  • Rename Channel.channelClients to channels

0.1.9 #

  • Fix channel update on message delete

0.1.8 #

  • Add delete message handling

0.1.7 #

  • Add reaction handling

0.1.6 #

  • Add initialized completer

  • Update example

0.1.5 #

  • Add ClientState and ChannelClientState classes to handle channel state updates using events

  • Update example supporting threads

0.1.4 #

  • Update some api with wrong or incomplete signatures

  • Add documentation for public apis

0.1.2 #

  • add websocket reconnection logic

  • add token expiration mechanism

0.1.1 #

  • add typing events handling

0.1.0 #

  • a better example can be found in the example/ directory

  • fix some api calls and add missing one

0.0.2 #

  • first beta version

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';

import 'channel_list_page.dart';
import 'stream_chat.dart';

void main() async {
  final client = Client(
    "qk4nn7rpcn75",
    logLevel: Level.INFO,
  );

  await client.setUser(
    User(id: "wild-breeze-7"),
    'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoid2lsZC1icmVlemUtNyJ9.VM2EX1EXOfgqa-bTH_3JzeY0T99ngWzWahSauP3dBMo',
  );

  runApp(StreamChat(
    child: MyApp(),
    client: client,
  ));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Stream Chat Example',
      home: ChatLoader(),
      theme: ThemeData(
        scaffoldBackgroundColor: Color(0xfff1f1f3),
        primaryColor: Color(0xfff1f1f3),
        accentColor: Color(0xff006bff),
        iconTheme: IconThemeData(
          color: Color(0xff006bff),
        ),
        floatingActionButtonTheme: FloatingActionButtonThemeData(
          foregroundColor: Color(0xff006bff),
        ),
        backgroundColor: Color(0xfff1f1f3),
        canvasColor: Color(0xfff1f1f3),
      ),
    );
  }

  @override
  void dispose() {
    StreamChat.of(context).dispose();
    super.dispose();
  }
}

class ChatLoader extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final streamChat = StreamChat.of(context);
    return StreamBuilder<User>(
      stream: streamChat.userStream,
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return Scaffold(
            body: Center(
              child: Text('${snapshot.error}'),
            ),
          );
        } else if (!snapshot.hasData) {
          return Scaffold(
            body: Center(
              child: CircularProgressIndicator(),
            ),
          );
        } else {
          return ChannelListPage(
            filter: {
              'members': {
                '\$in': [StreamChat.of(context).user.id],
              }
            },
            sort: [SortOption("last_message_at")],
            pagination: PaginationParams(
              limit: 20,
            ),
          );
        }
      },
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  stream_chat: ^0.1.30

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:stream_chat/stream_chat.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on May 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
async ^2.4.0 2.4.1
dio ^3.0.9 3.0.9
flutter 0.0.0
json_annotation ^3.0.1 3.0.1
logging ^0.11.4 0.11.4
rxdart ^0.24.0 0.24.1
stream_channel ^2.0.0 2.0.0
uuid ^2.0.4 2.0.4
web_socket_channel ^1.1.0 1.1.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.5
http_parser 3.1.4
meta 1.1.8
path 1.7.0
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner ^1.8.1
flutter_test
json_serializable ^3.3.0
mockito ^4.1.1
pedantic ^1.8.0+1