stream_chat 0.0.2 copy "stream_chat: ^0.0.2" to clipboard
stream_chat: ^0.0.2 copied to clipboard

outdated

The official Dart client for Stream Chat, a service for building chat applications.

example/lib/main.dart

import 'dart:async';

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

import 'components/channel_list.dart';
import 'components/stream_chat_container.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var client = Client("6xjf3dex3n7d");

    return StreamChatContainer(
      child: MaterialApp(
        title: 'Stream Chat Example',
        home: ChatLoader(
          child: ChannelList(
            filter: Map<String, dynamic>(),
            sort: [SortOption("last_message_at")],
            options: {},
          ),
          user: User(id: "wild-breeze-7"),
          token:
              "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoid2lsZC1icmVlemUtNyJ9.VM2EX1EXOfgqa-bTH_3JzeY0T99ngWzWahSauP3dBMo",
        ),
      ),
      client: client,
    );
  }
}

class ChatLoader extends StatefulWidget {
  final Widget child;
  final String token;
  final User user;

  ChatLoader({@required this.child, @required this.user, @required this.token});

  @override
  State createState() => ChatLoaderState();
}

class ChatLoaderState extends State<ChatLoader> {
  Future<dynamic> setUser;

  @override
  void didChangeDependencies() {
    setUser = StreamChatContainer.of(context)
        .client
        .setUser(widget.user, widget.token);
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<dynamic>(
        future: setUser,
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return widget.child;
          }
          if (snapshot.hasError) {
            return Text(snapshot.error.toString());
          }
          return CircularProgressIndicator();
        });
  }
}
64
likes
0
pub points
89%
popularity

Publisher

verified publishergetstream.io

The official Dart client for Stream Chat, a service for building chat applications.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

async, dio, flutter, json_annotation, logging, stream_channel, uuid, web_socket_channel

More

Packages that depend on stream_chat