diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index add7173b..6e696e54 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,13 +2,11 @@
-
-
-
+
@@ -24,17 +22,17 @@
-
-
+
+
-
+
-
-
+
+
@@ -45,8 +43,8 @@
-
-
+
+
@@ -57,8 +55,8 @@
-
-
+
+
@@ -69,8 +67,8 @@
-
-
+
+
@@ -78,7 +76,7 @@
-
+
@@ -93,8 +91,8 @@
-
-
+
+
@@ -147,6 +145,9 @@
CHANNEL-
_userController
onTap
+ _channelPreviewBuilder
+ onChannelTap
+ stack
@@ -165,14 +166,14 @@
-
+
+
+
-
-
@@ -431,13 +432,6 @@
-
-
-
-
-
-
-
@@ -445,33 +439,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -482,23 +449,20 @@
-
+
-
-
+
+
-
+
-
+
-
-
-
-
-
+
+
@@ -512,5 +476,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/example/lib/multiple_conversation.dart b/example/lib/multiple_conversation.dart
index 99fcfa0f..682f364f 100644
--- a/example/lib/multiple_conversation.dart
+++ b/example/lib/multiple_conversation.dart
@@ -9,18 +9,11 @@ void main() async {
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoid2lsZC1icmVlemUtNyJ9.VM2EX1EXOfgqa-bTH_3JzeY0T99ngWzWahSauP3dBMo',
);
- final channelClient = client.channel('messaging', id: 'godevs');
-
- channelClient.watch();
-
runApp(
StreamChat(
client: client,
child: MaterialApp(
- home: StreamChat(
- client: client,
- child: ChannelListPage(),
- ),
+ home: ChannelListPage(),
),
),
);
@@ -40,14 +33,7 @@ class ChannelListPage extends StatelessWidget {
pagination: PaginationParams(
limit: 20,
),
- onChannelTap: (channelClient) {
- Navigator.push(context, MaterialPageRoute(builder: (context) {
- return StreamChannel(
- child: ChannelPage(),
- channelClient: channelClient,
- );
- }));
- },
+ channelWidget: ChannelPage(),
),
);
}
diff --git a/example/lib/single_conversation.dart b/example/lib/single_conversation.dart
index 9fba044c..b0008765 100644
--- a/example/lib/single_conversation.dart
+++ b/example/lib/single_conversation.dart
@@ -14,10 +14,10 @@ void main() async {
channelClient.watch();
runApp(
- MaterialApp(
- home: StreamChat(
- client: client,
- child: StreamChannel(
+ StreamChat(
+ client: client,
+ child: MaterialApp(
+ home: StreamChannel(
channelClient: channelClient,
child: ChannelPage(),
),
diff --git a/lib/src/channel_list_view.dart b/lib/src/channel_list_view.dart
index 4a484921..94272044 100644
--- a/lib/src/channel_list_view.dart
+++ b/lib/src/channel_list_view.dart
@@ -5,19 +5,19 @@ import 'channel_preview.dart';
import 'stream_channel.dart';
import 'stream_chat.dart';
-typedef ChannelPreviewBuilder = Widget Function(BuildContext, ChannelState);
-typedef ChannelTapCallback = void Function(ChannelClient);
+typedef ChannelTapCallback = void Function(ChannelClient, Widget);
class ChannelListView extends StatefulWidget {
ChannelListView({
Key key,
- ChannelPreviewBuilder channelPreviewBuilder,
this.filter,
this.options,
this.sort,
this.pagination,
this.onChannelTap,
- }) : _channelPreviewBuilder = channelPreviewBuilder,
+ this.channelWidget,
+ this.channelPreview,
+ }) : assert(channelWidget != null || onChannelTap != null),
super(key: key);
final Map filter;
@@ -26,8 +26,8 @@ class ChannelListView extends StatefulWidget {
final PaginationParams pagination;
final ScrollController _scrollController = ScrollController();
final ChannelTapCallback onChannelTap;
-
- final ChannelPreviewBuilder _channelPreviewBuilder;
+ final Widget channelWidget;
+ final Widget channelPreview;
@override
_ChannelListViewState createState() => _ChannelListViewState();
@@ -98,17 +98,47 @@ class _ChannelListViewState extends State {
final channelClient =
streamChat.client.channelClients[channelState.channel.id];
+ ChannelTapCallback onTap;
+ if (widget.onChannelTap != null) {
+ onTap = widget.onChannelTap;
+ } else {
+ onTap = (client, _) {
+ Navigator.push(
+ context,
+ MaterialPageRoute(
+ builder: (context) {
+ return StreamChannel(
+ child: widget.channelWidget,
+ channelClient: client,
+ );
+ },
+ ),
+ );
+ };
+ }
+
Widget child;
- if (widget._channelPreviewBuilder != null) {
- child = GestureDetector(
- onTap: () {
- widget.onChannelTap(channelClient);
- },
- child: widget._channelPreviewBuilder(context, channelState),
+ if (widget.channelPreview != null) {
+ child = Stack(
+ children: [
+ widget.channelPreview,
+ Positioned.fill(
+ child: Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onTap: () {
+ onTap(channelClient, widget.channelWidget);
+ },
+ ),
+ ),
+ ),
+ ],
);
} else {
child = ChannelPreview(
- onTap: widget.onChannelTap,
+ onTap: (channelClient) {
+ onTap(channelClient, widget.channelWidget);
+ },
);
}
diff --git a/lib/src/channel_preview.dart b/lib/src/channel_preview.dart
index e1578ea2..e390a9f6 100644
--- a/lib/src/channel_preview.dart
+++ b/lib/src/channel_preview.dart
@@ -4,17 +4,16 @@ import 'package:flutter/widgets.dart';
import 'package:stream_chat/stream_chat.dart';
import 'channel_image.dart';
-import 'channel_list_view.dart';
import 'channel_name_text.dart';
import 'stream_channel.dart';
import 'stream_chat.dart';
class ChannelPreview extends StatelessWidget {
- final ChannelTapCallback onTap;
+ final void Function(ChannelClient) onTap;
const ChannelPreview({
Key key,
- @required this.onTap,
+ this.onTap,
}) : super(key: key);
@override
diff --git a/lib/stream_chat_flutter.dart b/lib/stream_chat_flutter.dart
index 05bf53da..37db4814 100644
--- a/lib/stream_chat_flutter.dart
+++ b/lib/stream_chat_flutter.dart
@@ -1,6 +1,7 @@
export 'package:stream_chat/stream_chat.dart';
export 'src/channel_list_view.dart';
+export 'src/channel_preview.dart';
export 'src/message_input.dart';
export 'src/message_list_view.dart';
export 'src/message_widget.dart';