diff --git a/stream_chat_v1/lib/custom_message.dart b/stream_chat_v1/lib/custom_message.dart deleted file mode 100644 index e275643..0000000 --- a/stream_chat_v1/lib/custom_message.dart +++ /dev/null @@ -1,124 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -/// Fifth step of the [tutorial](https://getstream.io/chat/flutter/tutorial/) -/// -/// Customizing how messages are rendered is another very common use-case that the SDK supports easily. -/// -/// Replace the built-in message component with your own is done by passing it as a builder function to the [MessageListView] widget. -/// -/// The message builder function will get the usual [BuildContext] argument as well as the [Message] object and its position inside the list. -/// -/// If you look at the code you can see that we use [StreamChat.of] to retrieve the current user so that we can style messages own messages in a different way. -/// -/// Since custom widgets and builders are always children of [StreamChat] or part of a [Channel], -/// you can use [StreamChat.of], [StreamChannel.of] and [StreamChatTheme.of] to use the API client directly -/// or to retrieve outer scope needed such as messages from the [Channel.state]. -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - runApp(MyApp(client)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - - MyApp(this.client); - - @override - Widget build(BuildContext context) { - return MaterialApp( - builder: (context, child) => StreamChat( - child: child, - client: client, - ), - home: ChannelListPage(), - ); - } -} - -class ChannelListPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - body: ChannelsBloc( - child: ChannelListView( - filter: { - 'members': { - '\$in': [StreamChat.of(context).user.id], - } - }, - sort: [SortOption('last_message_at')], - pagination: PaginationParams( - limit: 20, - ), - channelWidget: ChannelPage(), - ), - ), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ChannelHeader(), - body: Column( - children: [ - Expanded( - child: MessageListView( - messageBuilder: _messageBuilder, - ), - ), - MessageInput(), - ], - ), - ); - } - - Widget _messageBuilder( - BuildContext context, - MessageDetails details, - List messages, - ) { - final message = details.message; - final isCurrentUser = StreamChat.of(context).user.id == message.user.id; - final textAlign = isCurrentUser ? TextAlign.right : TextAlign.left; - final color = isCurrentUser ? Colors.blueGrey : Colors.blue; - - return Padding( - padding: EdgeInsets.all(5.0), - child: Container( - decoration: BoxDecoration( - border: Border.all(color: color, width: 1), - borderRadius: BorderRadius.all( - Radius.circular(5.0), - ), - ), - child: ListTile( - title: Text( - message.text, - textAlign: textAlign, - ), - subtitle: Text( - message.user.extraData['name'], - textAlign: textAlign, - ), - ), - ), - ); - } -} diff --git a/stream_chat_v1/lib/custom_theme.dart b/stream_chat_v1/lib/custom_theme.dart deleted file mode 100644 index a7ad5ba..0000000 --- a/stream_chat_v1/lib/custom_theme.dart +++ /dev/null @@ -1,148 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -/// Sixth step of the [tutorial](https://getstream.io/chat/flutter/tutorial/) -/// -/// The Flutter SDK comes with a fully designed set of widgets which you can customize to fit with your application style and typography. -/// Changing the theme of Chat widgets works in a very similar way that [MaterialApp] and [Theme] do. -/// -/// Out of the box all chat widgets use their own default styling, there are two ways to change the styling: -/// -/// 1. Initialize the [StreamChatTheme] from your existing [MaterialApp] style -/// 2. Construct a custom theme and provide all the customizations needed -/// -/// First we create a new Material [Theme] and pick [Colors.green] as swatch color. The theme is then passed to [MaterialApp] as usual. -/// -/// Then we create a new [StreamChatTheme] from the green theme we just created. -/// After saving the app you will see the UI will update several widgets to match with the new color. -/// -/// We also change the message color posted by the current user. -/// You can perform these more granular style changes using [StreamChatTheme.copyWith]. -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - runApp(MyApp(client)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - - MyApp(this.client); - - @override - Widget build(BuildContext context) { - final themeData = ThemeData(primarySwatch: Colors.green); - final defaultTheme = StreamChatThemeData.fromTheme(themeData); - final colorTheme = defaultTheme.colorTheme; - final customTheme = defaultTheme.merge(StreamChatThemeData( - ownMessageTheme: MessageTheme( - messageBackgroundColor: colorTheme.black, - messageText: TextStyle( - color: colorTheme.white, - ), - avatarTheme: AvatarTheme( - borderRadius: BorderRadius.circular(8), - ), - ), - )); - - return MaterialApp( - theme: themeData, - builder: (context, child) { - return StreamChat( - child: child, - client: client, - streamChatThemeData: customTheme, - ); - }, - home: ChannelListPage(), - ); - } -} - -class ChannelListPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - body: ChannelsBloc( - child: ChannelListView( - filter: { - 'members': { - '\$in': [StreamChat.of(context).user.id], - } - }, - sort: [SortOption('last_message_at')], - pagination: PaginationParams( - limit: 20, - ), - channelWidget: ChannelPage(), - ), - ), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ChannelHeader(), - body: Column( - children: [ - Expanded( - child: MessageListView( - threadBuilder: (_, parentMessage) { - return ThreadPage( - parent: parentMessage, - ); - }, - ), - ), - MessageInput(), - ], - ), - ); - } -} - -class ThreadPage extends StatelessWidget { - final Message parent; - - ThreadPage({ - Key key, - this.parent, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ThreadHeader( - parent: parent, - ), - body: Column( - children: [ - Expanded( - child: MessageListView( - parentMessage: parent, - ), - ), - MessageInput( - parentMessage: parent, - ), - ], - ), - ); - } -} diff --git a/stream_chat_v1/lib/customize_channel_preview.dart b/stream_chat_v1/lib/customize_channel_preview.dart deleted file mode 100644 index 2f28fa8..0000000 --- a/stream_chat_v1/lib/customize_channel_preview.dart +++ /dev/null @@ -1,136 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -/// Third step of the [tutorial](https://getstream.io/chat/flutter/tutorial/) -/// -/// So far you’ve learned how to use the default widgets. -/// The library has been designed with composition in mind and to allow all common customizations to be very easy. -/// This means that you can change any component in your application by swapping the default widgets with the ones you build yourself. -/// -/// Let’s see how we can make some changes to the SDK’s UI components. -/// We start by changing how channel previews are shown in the channel list and include the number of unread messages for each. -/// -/// We're passing a custom widget to [ChannelListView.channelPreviewBuilder], this will override the default [ChannelPreview] and allows you to create one yourself. -/// -/// There are a couple interesting things we do in this widget: -/// -/// - Instead of creating a whole new style for the channel name, we inherit the text style from the parent theme ([StreamChatTheme.of]) and only change the color attribute -/// -/// - We loop over the list of channel messages to search for the first not deleted message ([Channel.state.messages]) -/// -/// - We retrieve the count of unread messages from [Channel.state] -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - runApp(MyApp(client)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - - MyApp(this.client); - - @override - Widget build(BuildContext context) { - return MaterialApp( - builder: (context, child) => StreamChat( - child: child, - client: client, - ), - home: ChannelListPage(), - ); - } -} - -class ChannelListPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - body: ChannelsBloc( - child: ChannelListView( - filter: { - 'members': { - '\$in': [StreamChat.of(context).user.id], - } - }, - channelPreviewBuilder: _channelPreviewBuilder, - sort: [SortOption('last_message_at')], - pagination: PaginationParams( - limit: 20, - ), - channelWidget: ChannelPage(), - ), - ), - ); - } - - Widget _channelPreviewBuilder(BuildContext context, Channel channel) { - final lastMessage = channel.state.messages.reversed - .firstWhere((message) => !message.isDeleted); - - final subtitle = (lastMessage == null ? "nothing yet" : lastMessage.text); - final opacity = channel.state.unreadCount > .0 ? 1.0 : 0.5; - - return ListTile( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) => StreamChannel( - child: ChannelPage(), - channel: channel, - ), - ), - ); - }, - leading: ChannelImage( - channel: channel, - ), - title: ChannelName( - textStyle: - StreamChatTheme.of(context).channelPreviewTheme.title.copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .black - .withOpacity(opacity), - ), - ), - subtitle: Text(subtitle), - trailing: channel.state.unreadCount > 0 - ? CircleAvatar( - radius: 10, - child: Text(channel.state.unreadCount.toString()), - ) - : SizedBox(), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ChannelHeader(), - body: Column( - children: [ - Expanded( - child: MessageListView(), - ), - MessageInput(), - ], - ), - ); - } -} diff --git a/stream_chat_v1/lib/customize_message_widget.dart b/stream_chat_v1/lib/customize_message_widget.dart deleted file mode 100644 index d19d602..0000000 --- a/stream_chat_v1/lib/customize_message_widget.dart +++ /dev/null @@ -1,135 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -/// Fifth step of the [tutorial](https://getstream.io/chat/flutter/tutorial/) -/// -/// Customizing how messages are rendered is another very common use-case that the SDK supports easily. -/// -/// Replace the built-in message component with your own is done by passing it as a builder function to the [MessageListView] widget. -/// -/// The message builder function will get the usual [BuildContext] argument as well as the [Message] object and its position inside the list. -/// -/// If you look at the code you can see that we use [StreamChat.of] to retrieve the current user so that we can style messages own messages in a different way. -/// -/// Since custom widgets and builders are always children of [StreamChat] or part of a [Channel], -/// you can use [StreamChat.of], [StreamChannel.of] and [StreamChatTheme.of] to use the API client directly -/// or to retrieve outer scope needed such as messages from the [Channel.state]. -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - runApp(MyApp(client)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - - MyApp(this.client); - - @override - Widget build(BuildContext context) { - return MaterialApp( - builder: (context, child) => StreamChat( - child: child, - client: client, - ), - home: Container( - child: ChannelListPage(), - ), - ); - } -} - -class ChannelListPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - body: ChannelsBloc( - child: ChannelListView( - filter: { - 'members': { - '\$in': [StreamChat.of(context).user.id], - } - }, - sort: [SortOption('last_message_at')], - pagination: PaginationParams( - limit: 20, - ), - channelWidget: ChannelPage(), - ), - ), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ChannelHeader(), - body: Column( - children: [ - Expanded( - child: MessageListView( - messageBuilder: _messageBuilder, - ), - ), - MessageInput(), - ], - ), - ); - } - - Widget _messageBuilder( - BuildContext context, - MessageDetails details, - List messages, - ) { - final message = details.message; - final color = details.isMyMessage ? Colors.red : Colors.blue; - if (message.isSystem) { - return SizedBox(); - } - return MessageWidget( - message: message, - messageTheme: details.isMyMessage - ? StreamChatTheme.of(context).ownMessageTheme - : StreamChatTheme.of(context).otherMessageTheme, - borderSide: BorderSide( - color: color, - width: 2, - ), - padding: const EdgeInsets.symmetric( - vertical: 2, - horizontal: 4, - ), - attachmentBorderSide: BorderSide( - color: color, - width: 2, - ), - attachmentPadding: EdgeInsets.all(8), - borderRadiusGeometry: BorderRadius.vertical( - top: !details.isLastUser ? Radius.circular(16) : Radius.zero, - bottom: !details.isNextUser ? Radius.circular(16) : Radius.zero, - ), - showSendingIndicator: false, - reverse: false, - showUserAvatar: - details.isNextUser ? DisplayWidget.hide : DisplayWidget.show, - showTimestamp: !details.isNextUser, - showUsername: !details.isNextUser, - showReactions: false, - ); - } -} diff --git a/stream_chat_v1/lib/multiple_conversation.dart b/stream_chat_v1/lib/multiple_conversation.dart deleted file mode 100644 index f810231..0000000 --- a/stream_chat_v1/lib/multiple_conversation.dart +++ /dev/null @@ -1,93 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -/// Second step of the [tutorial](https://getstream.io/chat/flutter/tutorial/) -/// -/// Most chat applications handle more than just one single conversation. -/// Apps like Facebook Messenger, Whatsapp and Telegram allows you to have multiple one to one and group conversations. -/// -/// Let’s find out how we can change our application chat screen to display the list of conversations and navigate between them. -/// -/// > Note: the SDK uses Flutter’s [Navigator] to move from one route to another, this allows us to avoid any boiler-plate code. -/// > Of course you can take total control of how navigation works by customizing widgets like [Channel] and [ChannelList]. -/// -/// If you run the application, you will see that the first screen shows a list of conversations, you can open each by tapping and go back to the list. -/// -/// Every single widget involved in this UI can be customized or swapped with your own. -/// -/// The [ChannelListPage] widget retrieves the list of channels based on a custom query and ordering. -/// In this case we are showing the list of channels the current user is a member and we order them based on the time they had a new message. -/// [ChannelListView] handles pagination and updates automatically out of the box when new channels are created or when a new message is added to a channel. -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - runApp(MyApp(client)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - - MyApp(this.client); - - @override - Widget build(BuildContext context) { - return MaterialApp( - builder: (context, child) => StreamChat( - client: client, - child: child, - ), - home: ChannelListPage(), - ); - } -} - -class ChannelListPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - body: ChannelsBloc( - child: ChannelListView( - filter: { - // 'members': { - // '\$in': [StreamChat.of(context).user.id], - // } - }, - sort: [SortOption('last_message_at')], - pagination: PaginationParams( - limit: 20, - ), - channelWidget: ChannelPage(), - ), - ), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ChannelHeader(), - body: Column( - children: [ - Expanded( - child: MessageListView(), - ), - MessageInput(), - ], - ), - ); - } -} diff --git a/stream_chat_v1/lib/single_conversation.dart b/stream_chat_v1/lib/single_conversation.dart deleted file mode 100644 index 66a1091..0000000 --- a/stream_chat_v1/lib/single_conversation.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -/// First step of the [tutorial](https://getstream.io/chat/flutter/tutorial/) -/// -/// There are three important things to notice that are common to all Flutter application using StreamChat: -/// -/// 1. The Dart API [StreamChatClient] is initialized with your API Key -/// 2. The current user is set by calling [StreamChatClient.setUser] -/// 3. The client is then passed to the top-level [StreamChat] widget -/// [StreamChat] is an inherited widget and must be the parent of all Chat related widgets. -/// -/// Please note that while Flutter can be used to build both mobile and web applications; -/// in this tutorial we focus on mobile, make sure when running the app you use a mobile device. -/// -/// Let's have a look at what we've built: -/// -/// - We set up the Chat [StreamChatClient] with the API key -/// -/// - We set the the current user for Chat with [StreamChatClient.setUser] and a pre-generated user token -/// -/// - We make [StreamChat] the root Widget of our application -/// -/// - We create a single [ChannelPage] widget under [StreamChat] with three widgets: [ChannelHeader], [MessageListView] and [MessageInput] -/// -/// If you now run the simulator you will see a single channel UI. -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - final channel = client.channel('messaging', id: 'godevs'); - - // ignore: unawaited_futures - channel.watch(); - - runApp(MyApp(client, channel)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - final Channel channel; - - MyApp(this.client, this.channel); - - @override - Widget build(BuildContext context) { - return MaterialApp( - builder: (context, widget) { - return StreamChat( - child: widget, - client: client, - ); - }, - home: StreamChannel( - channel: channel, - child: ChannelPage(), - ), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ChannelHeader(), - body: Column( - children: [ - Expanded( - child: MessageListView(), - ), - MessageInput(), - ], - ), - ); - } -} diff --git a/stream_chat_v1/lib/split_view.dart b/stream_chat_v1/lib/split_view.dart deleted file mode 100644 index 0832475..0000000 --- a/stream_chat_v1/lib/split_view.dart +++ /dev/null @@ -1,139 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - runApp(MyApp(client)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - - MyApp(this.client); - - @override - Widget build(BuildContext context) { - return MaterialApp( - builder: (context, child) => StreamChat( - child: child, - client: client, - ), - home: SplitView(), - ); - } -} - -class SplitView extends StatefulWidget { - @override - _SplitViewState createState() => _SplitViewState(); -} - -class _SplitViewState extends State { - Channel selectedChannel; - - @override - Widget build(BuildContext context) { - return Flex( - direction: Axis.horizontal, - children: [ - Flexible( - child: ChannelListPage( - onTap: (channel) { - setState(() { - selectedChannel = channel; - }); - }, - ), - flex: 1, - ), - Flexible( - child: Scaffold( - body: selectedChannel != null - ? StreamChannel( - key: ValueKey(selectedChannel.cid), - child: ChannelPage(), - channel: selectedChannel, - ) - : Center( - child: Text( - 'Pick a channel to show the messages 💬', - style: Theme.of(context).textTheme.headline5, - ), - ), - ), - flex: 2, - ), - ], - ); - } -} - -class ChannelListPage extends StatelessWidget { - final void Function(Channel) onTap; - - ChannelListPage({this.onTap}); - - @override - Widget build(BuildContext context) { - return Scaffold( - body: ChannelsBloc( - child: ChannelListView( - onChannelTap: onTap != null - ? (channel, _) { - onTap(channel); - } - : null, - filter: { - 'members': { - '\$in': [StreamChat.of(context).user.id], - } - }, - sort: [SortOption('last_message_at')], - pagination: PaginationParams( - limit: 20, - ), - ), - ), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Navigator( - onGenerateRoute: (settings) { - return MaterialPageRoute( - builder: (context) { - return Scaffold( - appBar: ChannelHeader( - showBackButton: false, - ), - body: Column( - children: [ - Expanded( - child: MessageListView(), - ), - MessageInput(), - ], - ), - ); - }, - ); - }, - ); - } -} diff --git a/stream_chat_v1/lib/threads.dart b/stream_chat_v1/lib/threads.dart deleted file mode 100644 index 6a3c776..0000000 --- a/stream_chat_v1/lib/threads.dart +++ /dev/null @@ -1,122 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:stream_chat_flutter/stream_chat_flutter.dart'; - -/// Fourth step of the [tutorial](https://getstream.io/chat/flutter/tutorial/) -/// -/// Stream Chat supports message threads out of the box. Threads allows users to create sub-conversations inside the same channel. -/// -/// Using threaded conversations is very simple and mostly a matter of plugging the [MessageListView] to another widget that renders the widget. -/// To make this simple, such a widget only needs to build [MessageListView] with the parent attribute set to the thread’s root message. -/// -/// Now we can open threads and create new ones as well, if you long press a message you can tap on Reply and it will open the same [ThreadPage]. -void main() async { - final client = StreamChatClient( - 's2dxdhpxd94g', - logLevel: Level.INFO, - ); - - await client.setUser( - User(id: 'super-band-9'), - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A', - ); - - runApp(MyApp(client)); -} - -class MyApp extends StatelessWidget { - final StreamChatClient client; - - MyApp(this.client); - - @override - Widget build(BuildContext context) { - return MaterialApp( - builder: (context, child) => StreamChat( - child: child, - client: client, - ), - home: Container( - child: ChannelListPage(), - ), - ); - } -} - -class ChannelListPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - body: ChannelsBloc( - child: ChannelListView( - filter: { - 'members': { - '\$in': [StreamChat.of(context).user.id], - } - }, - sort: [SortOption('last_message_at')], - pagination: PaginationParams( - limit: 20, - ), - channelWidget: ChannelPage(), - ), - ), - ); - } -} - -class ChannelPage extends StatelessWidget { - const ChannelPage({ - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ChannelHeader(), - body: Column( - children: [ - Expanded( - child: MessageListView( - threadBuilder: (_, parentMessage) { - return ThreadPage( - parent: parentMessage, - ); - }, - ), - ), - MessageInput(), - ], - ), - ); - } -} - -class ThreadPage extends StatelessWidget { - final Message parent; - - ThreadPage({ - Key key, - this.parent, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: ThreadHeader( - parent: parent, - ), - body: Column( - children: [ - Expanded( - child: MessageListView( - parentMessage: parent, - ), - ), - MessageInput( - parentMessage: parent, - ), - ], - ), - ); - } -}