123 lines
2.9 KiB
Dart
123 lines
2.9 KiB
Dart
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 = Client(
|
||
's2dxdhpxd94g',
|
||
logLevel: Level.INFO,
|
||
);
|
||
|
||
await client.setUser(
|
||
User(id: 'super-band-9'),
|
||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A',
|
||
);
|
||
|
||
runApp(MyApp(client));
|
||
}
|
||
|
||
class MyApp extends StatelessWidget {
|
||
final Client 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: <Widget>[
|
||
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: <Widget>[
|
||
Expanded(
|
||
child: MessageListView(
|
||
parentMessage: parent,
|
||
),
|
||
),
|
||
MessageInput(
|
||
parentMessage: parent,
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|